Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jamie的Codeigniter MY_模型_Codeigniter_Codeigniter 2 - Fatal编程技术网

Jamie的Codeigniter MY_模型

Jamie的Codeigniter MY_模型,codeigniter,codeigniter-2,Codeigniter,Codeigniter 2,这快把我逼疯了 我重新安装了CI 2.1.3。 从此处复制了我的_模型: 到应用程序/核心。 在autoload.php中自动加载的数据库库 在config文件夹中正确配置了database.php 扩展MY_模型类,如下所示: class User_m extends MY_Model{ public $_table = 'user'; public $primary_key = 'user_id'; } 在默认控制器中: $this->load->mode

这快把我逼疯了

我重新安装了CI 2.1.3。
从此处复制了我的_模型: 到应用程序/核心。
autoload.php中自动加载的数据库
在config文件夹中正确配置了database.php

扩展MY_模型类,如下所示:

class User_m extends MY_Model{ 

    public $_table = 'user';
    public $primary_key = 'user_id';

}
在默认控制器中:

$this->load->model('user_m', 'user');

$row = $this->user->get(1);
echo $row->email;
这是查看CRUD库如何工作的最简单实现,但我得到以下错误:

Fatal error: Call to a member function where() on a non-object in MY_Model.php on line 135  
MY_Model.php的第135行:

$row = $this->_database->where($this->primary_key, $primary_value)
                        ->get($this->_table)
                        ->{$this->_return_type()}();
$this->load->database()不会返回任何数据库对象

从CI文档:

/**  
 * Database Loader  
 *  
 * @param    mixed   $params     Database configuration options  
 * @param    bool    $return     Whether to return the database object  
 * @param    bool    $query_builder  Whether to enable Query Builder  
 *                   (overrides the configuration setting)  
 *  
 * @return   void|object|bool    Database object if $return is set to TRUE,  
 *                   FALSE on failure, void in any other case  
 */  
 public function database($params = '', $return = FALSE, $query_builder = NULL) 
尝试:

if ( $this->db ) {
    $this->_database = $this->db;
} else {
    $this->_database = $this->load->database('default', true, true);
}
以后编辑:

我找到了那个模型的固定版本。将您的核心模型替换为

在不重命名模型的情况下尝试:
$this->user\m->get(1)-可能是扩展模型不支持重命名。类的_set_数据库函数一定有问题。我不知道为什么会有这个函数,因为您可以从CI配置文件加载数据库。第135行是什么?并且应该
$this->load->model('user\m','user')
be
$this->load->model(数组('user\m','user'))将两个模型封装在一个数组中,用第135行更新了问题。至于模型加载。如果没有建立数据库连接,您可以检查连接是否成功吗?很抱歉加载我以为你加载了两个模型,如果你忘记了第二个参数正在重命名的话。我想就是问题所在。非常感谢。
if ( $this->db ) {
    $this->_database = $this->db;
} else {
    $this->_database = $this->load->database('default', true, true);
}