2014-09-24 123 views
0

我有兩個不同的模型文件與一個共同的功能。如何在另一個模型類中調用一個模型類的功能?

所以我寫了函數試圖通過使用訪問另一個模型文件:

$this->load->model('model_1'); 
$this->model_1->com_fun(); 

但它無法正常工作。我如何在另一個模型類中調用一個模型類的功能?

+0

檢查了這一點http://stackoverflow.com/問題/ 872623/access-codeigniter-models-in-other-models – 2014-09-24 11:15:08

+0

我以同樣的方式在user_model中加載模型model_1 – 2014-09-24 11:22:19

+0

codeigniter的版本是什麼?// – 2014-09-24 11:28:16

回答

1

有時是有用的在你的控制器是這樣的:

public function __construct(){ 

    $this->CI =& get_instance(); 
} 

所以,當你需要另一種模式,你可以這樣做:

$this->CI->load->model('another_codeigniter_model_name', 'another'); 
$something = $this->CI->another->com_fun(); 
相關問題