2010-04-28 4 views
0

바라건대 간단한 질문입니다. 나는 테이블 세트 (kb_items, kb_item_tags 등)를 사용하는 플러그인을 가지고 있습니다. 나는 따라서, (내 페이지 컨트롤러, 말) 다른 컨트롤러에서이 모델에 액세스 할 수 있도록하고 싶습니다 :PHP 케이크 1.1 일반 컨트롤러에서 플러그인 모델에 액세스하는 방법

class PagesController extends AppController{ 

function knowledgebase(){ 
    $items = $this->KbItem->findAll(...); 
} 

} 

을 나는 인정 하듯이 지식 기반 내에서이 컨트롤러를 배치하지 않음으로써 (규칙 약간을 위반하고 플러그인)이지만이 경우에는 지식 기반 플러그인 코드베이스의 일부가 될 필요가없는 사용자 정의 페이지입니다.

자세한 내용이 필요하면 알려주십시오. 어떤 도움을 주셔서 미리 감사드립니다! 가 1.1에서 다음과 같이 작동하는 경우

class PagesController extends AppController 
{ 
    var $uses = array('Page','KbItem'); 

    function knowledgebase() 
    { 
     // This now works 
     $items = $this->KbItem->findAll(); 
    } 
} 

답변

0

그냥 컨트롤러의 $uses 속성에 모델을 추가 배열을 사용합니다 :

class PagesController extends AppController 
{ 
    var $uses = array('Page','Kb.KbItem'); 

    function knowledgebase() 
    { 
     // This now works 
     $items = $this->KbItem->findAll(); 
    } 
} 
1

확실하지하지만 1.2+에서 당신은 플러그인 이름과 모델명과 컨트롤러의에서 기간을 접두사 :

2

나는이 작업을 직접 수행해야했으며 'Uses'배열에 모델 이름을 넣으면됩니다. 여러 컨트롤러 액션에서 모델에 액세스 할 필요가없는 경우 loadModel()을 사용하여 필요한 액션으로 액세스 할 수도 있습니다. 예를 들어 주어진 컨트롤러의 view() 액션에서이 모델에 액세스하기 만하면된다고 가정 해 봅시다 :

function view() { 
    // load the model, making sure to add the plug-in name before the model name 
    // I'm presuming here that the model name is just 'Item', and your plug-in is called 'Kb' 
    $this->loadModel('Kb.Item'); 

    // now we can use the model like we normally would, just calling it 'Item' 
    $results = $this->Item->find('all'); 
    } 

희망이 있습니다.

관련 문제