Very frustrating -
When I'm developing locally everything works perfect . I then started testing on my host (GoDaddy) for the first time and I get the error
Fatal error: Class 'MY_Model' not found in /home/content/49/12220009/html/application/models/user_model.php on line 3
The code is very basic -
User_model.php
class User_model extends MY_Model {
protected $_table;
public function __construct() {
parent::__construct();
$this->_table = "user";
}
MY_Model.php (application/core/My_Model.php)
class MY_Model extends CI_Model
{
public function __construct() {
echo "in my model ctor";
parent::__construct();
}
And it all starts with a controller loading User_model as expected -
$this->load->model('user_model');
Any thoughts on why this would work locally but not on my host , or how to solve it in other words?
it is definitely a case-sensitivity issue; what you should do is follow these two steps
1.follow these conventions and you are good to go
class Model_name extends CI_Model
Model_name is the name of your class... Class names must have the first letter capitalized with the rest of the name lowercase
and then the file name should be in lower case like this
application/models/model_name.php
This also happened to me:
on Linux system ,it show the error you specify while on window it was fine.
this is because Linux is case sensitivity .
what i did?;
I rename the file from /core/MY_model to /core/MY_Model.
and ,then it solved my problem .
CodeIgniter 3 solution
The class name and the class filename must have an uppercase first character.
Starting with CodeIgniter 3.0, all class filenames (libraries,
drivers, controllers and models) must be named in a Ucfirst-like
manner or in other words - they must start with a capital letter.
For example, if you have the following library file:
application/libraries/mylibrary.php
… then you’ll have to rename it to:
application/libraries/Mylibrary.php
Related
After Hosting Php codeignitor website I Got a Error "Unable to locate the model you have specified: Common_model"
But Its Works in my local server
How I can solve this issue
I already change First letter of the model class name capitalized but no result
my model class
class Common_model extends CI_Model
{
}
and controller is
<?php
class Show extends CI_Controller
{ var $pageLimit = 6;
public function __construct()
{
parent::__construct();
$this->load->library('ion_auth');
$this->load->model('common/Common_model');
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('custom');
}
}
If you are are using Codeignitor 3 than make sure you file name also start with capital letter as:
Common_model.php
It's recommended to use your models inside the model folder not model/anyfolder
Codeignitor 3 Change Log User Manual
I hope Your model file structure is like
application
model
common
Common_model.php
File name should be Common_model.php.
Load in Controller should be
$this->load->model('common_model');
I always load it with the name only, this way
$this->load->model('Common_model');
Always the controller is on the same module (if you are using modules)
I am aware of the other questions on the platform for this issue however I am having a very unusual issue with this.
I have a model Company_Model.php which is being autoloaded in the autoload.php and the Class is built like this:
Class Company_Model extends CI_Model {
function __construct()
{
parent::__construct();
}
public function foo()
{
echo 'bar';
}
}
However I am still getting this error when I load the page:
I am running on Apache 2, PHP 5.5.9 on Ubuntu 14.04, I cannot find an error log for this issue and now I am baffled, any help would be gratefully recieved.
I have check the uppercasing and all of the other tips from StackOverflow but still no joy.
Edit
Auto load code
$autoload['model'] = array('company_model');
When you use codeigniter 3 you have to make sure your class names and file names only have the first letter upper case as explained here
Class Naming Style Guide
Filename Style Guide
<?php
class Company_model extends CI_Model {
}
And file name then should be Company_model.php
$autoload['model'] = array('company_model');
If in sub folder
models > sub folder > Company_model.php
$autoload['model'] = array('subfolder/company_model');
If need to call it on controller only
$this->load->model('company_model');
$this->company_model->function();
Sub folder
$this->load->model('subfolder/company_model');
$this->company_model->function();
Make sure your class name and file name should be same and first Letter should be Capital
Example
class Login extends CI_Model{
//some code
}
above code, you can see the class Login first letter is capital.same name you have save of your model file name like Login.php in the model directory of your project folder
Try Changing the class name Company_Model to Company_model and also change your file name Company_Model.php to company_model.php
I'm getting an unable to locate model error.
$this->load->model('1/Gift_model');
My model file name is gift_model.php within /models/1/.
I declare the model the following way.
class Gift_model extends CI_Model {
According to CodeIgniter's documentation I'm doing it the correct way. Any suggestions? I have 5 other models named exactly the same way and they're all loading fine.
Make the model class name Uppercase My_model
Make the model php file name Lowercase my_model
Load the model using Lowercase (file name) $this->load->model('my_model');
$this->load->model('1/Gift_model'); should be $this->load->model('1/gift_model');. Lowercase on this load argument and the php filename, uppercase on the class name within the file (you had two of three correct).
http://www.codeigniter.com/userguide3/installation/upgrade_300.html
Starting with CodeIgniter 3.0, all class filenames (libraries, drivers, controllers and models) must be named in a Ucfirst-like manner or in other words - they must start with a capital letter.
Used to be the model files started with lower case, but they changed it.
Ensure that the the model name is Gift_model and the class name is also Gift_model
class Gift_model extends CI_Model
{
}
but loading the class is '1/gift_model' NOT 'Gift_model'
$this->load->model('1/gift_model');
hope this was helpful
The problem is that your file name is all lowercase (gift_model.php) while you are loading Gift_model within CodeIgniter. Either change the file name to Gift_model.php or update your code accordingly.
Are you calling the parent's constructor for the model?
class Gift_model extends CI_Model {
function __construct()
{
parent::__construct();
}
-> Model Class name must be Uppercase
-> Model PHP file name must be Lowercase
-> Load Model using Lowercase(filename): $this->load->model('gift_model', TRUE);
Starting with CodeIgniter 3.0, all class filenames (libraries, drivers, controllers and models) must be named in a Ucfirst-like manner or in other words - they must start with a capital letter.
(Source: CI docs)
`if using codeignitor 3.1.3
every thing same otherwise showing error
class name => My_model
file name => My_model.php
load model => $this->load->model('My_model');
call function => $this->My_model->function();`
I am developing on codeigniter from last two months. But when I pushed my code to Web hosting site today, I am getting this error. Few things I have checked 100 times:
Controller method says $this->load->model('myModel');
In the model folder I have myModel.php
It starts with
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');<br/>
class MyModel extends CI_Model {
public function __construct()
{
parent::__construct();
}
I have checked spelling mistakes or some typo but everything seems to be fine.
A name of model should be lower case: mymodel_model.php on /application/models/ directory.
The mymodel_model.php contains:
class Mymodel_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
And call it as:
$this->load->model('mymodel');
A _model string MUST be on:
filename of model mymodel_model.php
a class name with first uppercase name class Mymodel_model
Full example on Codeigniter manual: http://ellislab.com/codeigniter/user-guide/general/models.html
make the name of your model lower case all ex: "mymodel.php" and then in autoload.php just put this code $autoload['libraries'] = array('session','database'); Just get the parent construct int the model and make it simplier like this code.
<?php
class MyModel extends CI_Model
{
public function functionName()
{
}
}
Model filename should be all lowercase. #ddjikic's reply was correct and _model is not necessary.
I am using codeigniter 3.0.0 and I just faced same issue in my application when I hosted it to the production site. I salved it using the capitalizing the filename (first letter) as mentioned in error.
The Capitalize and lowercase filenames are dependent on different hosting servers.
I just made the filename's first letter capital and it works fine for me. I don't know what settings my hosting server have. but it worked for me.
You can also try, hope it can salve your error.
Example:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Enquiry_model extends CI_Model
{
}
As in above example my filename was enquiry_model.php when it gives me error.
But later I renamed it to Enquiry_model.php and it salved my error.
i have written a small codeigniter test app that is currently running on my windows box.
i created a linux vm and have tried to install the app on this new virtual server.
some of my web app is running properly but other parts, no.
specifically, this works:
http://123.123.123.123/myapp/controller1/
but this does not:
http://123.123.123.123/myapp/controller2/mymethod/1/2/3
It fails with an error that it can't load controller2_model.
Here's the actual code for the controller that is failing (it's really called xferLogger vs. controller2):
class xferLogger extends CI_Controller {
public function __construct() {
parent::__construct();
echo(2);
$this->load->model('xferLogger_model');
$this->load->helper('date'); //this library is needed for the base_url() method that is being called in the view "result.php"
$this->load->helper('url');
}
and here's the model:
class xferLogger_model extends CI_Model {
public function __construct() {
$this->load->database();
}
The full error message is: An error was encountered. Unable to locate the model you have specified: xferlogger_model.
Here's something I noticed. in the error message, you'll notice that the "L" in logger is lowercase. but in my code, it's a capital L.
I've checked in my controller, the model itself, and also the routes.php file. I can't seem to find any problems with my casing.
??
From the userguide: Class names must have the first letter capitalized with the rest of the name lowercase. So therefore:
class Xferlogger_model extends CI_Model // First letter capitalised
and your model load
$this->load->model('xferlogger_model'); // lower case
and your PHP filename
xferlogger_model.php // lower case
Codeigniter Model Userguide