Php Codeigniter HMVC:模型中未定义的属性$db
以下是Php Codeigniter HMVC:模型中未定义的属性$db,php,codeigniter-3,codeigniter-hmvc,Php,Codeigniter 3,Codeigniter Hmvc,以下是modules文件夹中的文件夹结构 用户->控制器->users.php 用户->模型->测试模型.php 欢迎->控制器->欢迎.php Test_model.php class Welcome extends MX_Controller { public function __construct() { parent::__construct(); $this->load->model('users/test_model')
modules
文件夹中的文件夹结构
class Welcome extends MX_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('users/test_model');
}
public function index()
{
//this will give the output
$this->test_model->test();
//thiw will throw error
$this->test_model->db_example();
}
类测试模型扩展了CI模型{
function __construct() {
parent::__construct();
}
public function db_example()
{
return $this->db->get('mir_users')->result();
}
public function test(){
echo 'test model call';
}
}
在Welcome.php中
class Welcome extends MX_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('users/test_model');
}
public function index()
{
//this will give the output
$this->test_model->test();
//thiw will throw error
$this->test_model->db_example();
}
$this->test\u model->test()
返回输出,但我将在db\u example
函数中得到错误
Message: Undefined property: Test::$db
在autoload.php中
$autoload['libraries'] = array('database');
我正在使用最新版本的HMVC
Codeigniter版本:3.1.0您已经在自动加载和模型注释中加载了两次数据库库
$this->load->database();
您已经在模型中的“自动加载”和“模型注释”这一行中加载了两次数据库库
$this->load->database();
最后我找到了解决办法。问题不在于我的代码。这是HMVC版本 对于codeigniter版本3.x,请使用此版本
但是我使用了错误的版本。最终我找到了解决方案。问题不在于我的代码。这是HMVC版本 对于codeigniter版本3.x,请使用此版本
但是我使用了错误的版本。模型中有名为users的文件夹吗?没有。
模型中没有文件夹。
文件夹$this->load->model('users/test_model');为什么要将用户放在这个语句中?这会从另一个模块加载一个模型在模型中有一个名为users的文件夹吗?不,在models
folder$this->load->model('users/test_model')中没有文件夹;为什么要将用户放入此语句中?这将从另一个模块加载模型