php Codeigniter 3 - 无法找到您指定的模型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31336621/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:23:02  来源:igfitidea点击:

Codeigniter 3 - Unable to locate the model you have specified

phpcodeigniter

提问by Justin Erswell

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.phpwhich is being autoloaded in the autoload.phpand the Class is built like this:

我有一个Company_Model.php正在自动加载的模型,autoload.php类是这样构建的:

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:

但是,当我加载页面时,我仍然收到此错误:

Codeignter 3 - Unable to locate the model you have specified

Codeignter 3 - 无法找到您指定的模型

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.

我在 Apache 2、Ubuntu 14.04 上的 PHP 5.5.9 上运行,我找不到此问题的错误日志,现在我很困惑,将不胜感激地收到任何帮助。

I have check the uppercasing and all of the other tips from StackOverflow but still no joy.

我已经检查了 StackOverflow 的大写和所有其他提示,但仍然没有任何乐趣。

Edit

编辑

Auto load code

自动加载代码

$autoload['model'] = array('company_model');

$autoload['model'] = array('company_model');

回答by Mr. ED

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

当您使用 codeigniter 3 时,您必须确保您的类名和文件名只有第一个字母大写,如此处所述

Class Naming Style Guide

类命名风格指南

Filename Style Guide

文件名样式指南

<?php

class Company_model extends CI_Model {

}

And file name then should be Company_model.php

然后文件名应该是Company_model.php

$autoload['model'] = array('company_model');

If in sub folder

如果在子文件夹中

models > sub folder > Company_model.php

模型 > 子文件夹 > 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();

回答by Mohammad Faisal

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 Loginfirst letter is capital.same name you have save of your model file name like Login.phpin the model directory of your project folder

上面的代码,你可以看到类的Login第一个字母是大写的。与你在项目文件夹的模型目录中保存的模型文件名相同的名称,如Login.php