2014-09-24 3 views
0

하나의 공통된 기능을 가진 두 개의 다른 모델 파일이 있습니다. 다른 모델 클래스에서 한 모델 클래스의 함수를 호출하는 방법은 무엇입니까?

는 그래서 사용하여 해당 액세스를 시도하는 다른 모델 파일에서 해당 기능을 작성 :

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

그러나 그것은 작동하지 않습니다. 다른 모델 클래스에서 한 모델 클래스의 함수를 어떻게 호출 할 수 있습니까?

+0

확인이를 http://stackoverflow.com/ 질문/872623/액세스 - codeigniter-models-in-other-models –

+0

나는 user_model –

+0

안에 model_1이라는 모델을로드 한 것과 같은 방법으로 코드 닉터 버전을 만들었습니까? // –

답변

1

때때로처럼 컨트롤러 무언가를하는 것이 유용하다 : 그래서

public function __construct(){ 

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

다른 모델을 필요로 할 때, 당신은 할 수 있습니다 :

$this->CI->load->model('another_codeigniter_model_name', 'another'); 
$something = $this->CI->another->com_fun(); 
관련 문제