php 无法找到您指定的模型 - CodeIgniter 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18882329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to locate the model you have specified - CodeIgniter Issue
提问by wwwroth
I'm getting an unable to locate model error.
我收到无法定位模型错误。
$this->load->model('1/Gift_model');
My model file name is gift_model.phpwithin /models/1/.
我的模型文件名为/models/1/ 中的gift_model.php。
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.
根据 CodeIgniter 的文档,我正在以正确的方式进行操作。有什么建议?我还有 5 个以完全相同的方式命名的模型,它们都加载良好。
回答by noelyahan
- 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');
- 使模型类名大写
My_model
- 使模型php文件名小写
my_model
- 使用小写(文件名)加载模型
$this->load->model('my_model');
回答by Aaron Martins
$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).
$this->load->model('1/Gift_model');
应该是$this->load->model('1/gift_model');
。此加载参数和 php 文件名小写,文件中的类名大写(三个中的两个是正确的)。
回答by Tel
http://www.codeigniter.com/userguide3/installation/upgrade_300.html
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.
从 CodeIgniter 3.0 开始,所有类文件名(库、驱动程序、控制器和模型)都必须以类似 Ucfirst 的方式命名,或者换句话说——它们必须以大写字母 开头。
Used to be the model files started with lower case, but they changed it.
曾经是模型文件以小写开头,但他们改变了它。
回答by jfindley
Ensure that the the model name is Gift_model and the class name is also Gift_model
确保模型名称为Gift_model,类名也是Gift_model
class Gift_model extends CI_Model
{
}
but loading the class is '1/gift_model' NOT 'Gift_model'
但加载类是“1/gift_model”而不是“Gift_model”
$this->load->model('1/gift_model');
hope this was helpful
希望这是有帮助的
回答by Prabhu Nandan Kumar
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.
从 CodeIgniter 3.0 开始,所有类文件名(库、驱动程序、控制器和模型)都必须以类似 Ucfirst 的方式命名,或者换句话说——它们必须以大写字母开头。
(来源:CI 文档)
回答by Mark
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.
问题是gift_model.php
当您Gift_model
在 CodeIgniter中加载时,您的文件名全是小写 ( ) 。将文件名更改为Gift_model.php
或相应地更新您的代码。
回答by jakobhans
Are you calling the parent's constructor for the model?
您是否正在为模型调用父级的构造函数?
class Gift_model extends CI_Model {
function __construct()
{
parent::__construct();
}
回答by Hardik Panseriya
-> Model Class name must be Uppercase
-> Model PHP file name must be Lowercase
-> Load Model using Lowercase(filename): $this->load->model('gift_model', TRUE);
回答by Bhale Dino
`if using codeignitor 3.1.3
every thing same otherwise showing error
class name => My_model
`如果使用 codeignitor 3.1.3
一切都一样,否则会显示错误类名 => My_model
file name => My_model.php
文件名 => My_model.php
load model => $this->load->model('My_model');
加载模型 => $this->load->model('My_model');
call function => $this->My_model->function();`
调用函数 => $this->My_model->function();`