這裏未定義的屬性$ DB是modules
文件夾中的文件夾結構笨HMVC:模型
用戶 - > controllers-> Users.php
用戶 - >模型 - > Test_model.php
welcome-> controllers->的welcome.php
Test_model.php
類Test_model擴展CI_Model {
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_model->test()
返回輸出,但我會得到錯誤在db_example
函數
Message: Undefined property: Test::$db
在autoload.php
$autoload['libraries'] = array('database');
我使用的是最新版本的HMVC
笨版本:3.1.0
在模型中是否有一個名爲users的文件夾? –
Nop在'models'文件夾中沒有文件夾 –
$ this-> load-> model('users/test_model');你爲什麼把用戶放在這個聲明中? –