2014-09-24 124 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(); 
相关问题