2016-08-23 73 views
1

這裏未定義的屬性$ DB是modules文件夾中的文件夾結構笨HMVC:模型

  1. 用戶 - > controllers-> Users.php

    用戶 - >模型 - > Test_model.php

  2. 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

+0

在模型中是否有一個名爲users的文件夾? –

+0

Nop在'models'文件夾中沒有文件夾 –

+0

$ this-> load-> model('users/test_model');你爲什麼把用戶放在這個聲明中? –

回答

0

您已在自動加載,並在加載數據庫庫兩次模型評論這條線在模型

$this->load->database(); 
+0

它已經完成但仍然是相同的錯誤 –