简体   繁体   English

无法找到您指定的codeigniter模型

[英]unable to locate the model you have specified codeigniter

I am unable to get model file User_model.php 我无法获得模型文件User_model.php

i have specified file in models/frontend/user_model.php 我已经在models/frontend/user_model.php指定了文件

Declaration in user_model.php 在user_model.php中声明

<?php

class User_model extends CI_Model {}

I have user model in Controller : 我在Controller中有用户模型:

<?php

class User_controller extends MY_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('frontend/user_model');
    }

This is correctly working on my localhost but when i host on my domain it gives such type of errors. 这在我的本地主机上正常工作,但是当我在我的域上托管时,会出现此类错误。

您需要将模型文件从user_model.php重命名为User_model.php。在Windows wampp或xampp中,大小写无关紧要,但是您的生产环境必须在Linux上并且区分大小写,这就是为什么会出现错误的原因。

Did you follow Codeigniter User Guide ? 您是否遵循Codeigniter用户指南

class User_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
}

Your file will be this: application/models/user_model.php 您的文件将为: application/models/user_model.php

If you use <? 如果使用<? as an opening tag (check at the very start of your file), change it to <?php . 作为开始标记(在文件的开头检查),将其更改为<?php The server might not allow the shorthand style. 服务器可能不允许使用速记样式。

And if you are still unlucky, try this: 如果您仍然不走运,请尝试以下操作:

 $CI =&get_instance();
 $CI->load->model('articles_model');
 $parameter = $CI->articles_model>getarticle($id);

When making or calling a class you have to use first letter capital of class. 上课或上课时,您必须使用班级的首字母大写。 Call your model like this. 这样称呼您的模型。

$this->load->model('frontend/User_model');

I faced this issue too. 我也面临这个问题。 We have to use first letter capital for classes in codigniter 3.0 or above. 在codigniter 3.0或更高版本中,我们必须对课程使用首字母大写。

Check for model name. 检查型号名称。 Case sensitive name ignored in localhost . 区分大小写的名称在localhost被忽略。 But in server they are treated as different file. 但是在服务器中,它们被视为不同的文件。 I can see your model name is user_model . 我可以看到您的模型名称是user_model But Model class is User_model which is in capital letter. 但是Model类是User_model ,用大写字母表示。 Hope this help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM