【问题标题】:Weird Issue with Codeigniter (Model Issue)Codeigniter 的奇怪问题(模型问题)
【发布时间】:2014-09-17 22:08:21
【问题描述】:

我已经在 Linux 机器上设置了 CodeIgniter 的本地副本和另一个副本。使用我的应用程序安装两个副本后,本地副本运行正常,但 linux 版本显示以下错误代码:

Unable to locate the model you have specified: User_model

我整天都在寻找这个问题的答案。我试图更改模型名称、文件名以及我能想到的所有内容的拼写。我可能缺少什么会显示该错误?

谢谢大家

这是我的代码的副本:

(user_model.php)

 <?php

class User_model extends CI_Model {
    public function __construct(){
        parent::__construct();
    }

    function runTest(){
        return "Testing";
    }
}
?>

(welcome.php)

class Welcome extends CI_Controller {
public function __construct(){
    parent::__construct();
}
public function index()
{
    $this->load->model('User_Model');
    $data['testing'] = $this->user1234->runTest();
    $this->load->view('welcome_message', $data);
}

}

【问题讨论】:

标签: php codeigniter web-applications


【解决方案1】:

这是因为区分大小写。首先,您应该将所有文件名保留为小写字母( user_model.php ),然后在控制器中使用该名称( $this->load->model('user_model'); )。

它必须有效。

【讨论】:

    【解决方案2】:

    感谢大家的帮助。显然,这是一个命名问题。我将文件名大写,在控制器中,它现在工作得很好。不知道安静下来是怎么回事。但是非常感谢你们。

    新代码如下所示:

    $this->load->model('User_model');
    $query = $this->User_model->validate();
    

    【讨论】:

      【解决方案3】:
           $this->load->model('User_Model');
          $data['testing'] = $this->user1234->runTest();
          $this->load->view('welcome_message', $data);
      

      你的第二行有错误 改成

      $data['testing'] = $this->user_model->runTest();
      

      【讨论】:

        猜你喜欢
        • 2011-01-01
        • 2016-12-01
        • 2015-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-19
        • 1970-01-01
        相关资源
        最近更新 更多