可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
回答1:
- 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');
回答2:
$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).
回答3:
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.
回答4:
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
回答5:
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.
回答6:
Are you calling the parent's constructor for the model?
class Gift_model extends CI_Model { function __construct() { parent::__construct(); }
回答7:
-> Model Class name must be Uppercase -> Model PHP file name must be Lowercase -> Load Model using Lowercase(filename): $this->load->model('gift_model', TRUE);
回答8:
`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();`
回答9:
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)