2010-03-19 6 views

답변

35

컨트롤러 개체에 대한 참조를 얻고이를 통해 모델에 액세스 할 수 있습니다.

function my_helper() 
{ 
    // Get a reference to the controller object 
    $CI = get_instance(); 

    // You may need to load the model if it hasn't been pre-loaded 
    $CI->load->model('my_model'); 

    // Call a function of the model 
    $CI->my_model->do_something(); 
} 

다른 옵션은 도우미 함수를 호출 할 때 모델을 전달하는 것입니다.

function my_helper($my_model) 
{ 
    $my_model->do_something(); 
} 

function my_controller_action() 
{ 
    // Call the helper function, passing in the model 
    my_helper($this->my_model); 
} 
+0

위대한 작품입니다. 왜 그런지 정말 궁금합니다. 나는 지금 그것을 사용하고있다. 그러나 내가하는 일을 성취 할 수있는 더 좋은 방법이 있다고 확신한다. 그래도 고마워! – qwerty

+1

위대한 작품 :) 고마워요! –

관련 문제