2013-11-21 34 views
0
我有問題要得到CakePHP的相關模型信息

殼,這是我的shell:CakePHP的1.3外殼沒有得到相關的模型

class ContactShell extends Shell{ 
    public $uses = array('Contact'); 

    public function main(){ 
     $contacts = $this->Contact->find('all', array(
        'conditions' => array(
        'Contact.is_sent' => false, 
        'Contact.is_bounce' => false), 
       'contain' => array('City' => array(
          'fields' => array('City.name'))))); 
     debug($contacts); 
    } 
} 

當我運行這個shell我得到錯誤

警告:模型「聯繫」是不是在C與模型「城市」有關:\ WAMP \ WWW \多哥 設計\蛋糕\庫\型號\行爲\ containable.php上線363

而結果只包含聯繫人模型數組。

控制器中的相同的腳本顯示我的城市陣列

如何獲得協會CakePHP的殼工作任何建議???

我也使用

$this->Contact->recursive = 1; 

回答

0

你加入中可容納的行爲,以接觸模型試過嗎?

public function main(){ 
    $this->Contact->Behaviors->attach('Containable'); 
    $contacts = $this->Contact->find('all', array(
       'conditions' => array(
        'Contact.is_sent' => false, 
        'Contact.is_bounce' => false), 
       'contain' => array('City' => array(
         'fields' => array('City.name'))))); 
} 

如果這行不通,我們需要看到您的聯繫型號

的定義