2012-07-13 57 views
-1

我用cakephp控制檯生成一些CRUD操作。生成的代碼很麻煩,因爲相關模型的模型在控制器中未默認加載。相關模型未加載由代碼生成的代碼php控制檯

例如:

$programs = $this->Chantier->Program->find('list'); 

是行不通的,但是:

$this->loadModel('Program'); 
$programs = $this->Program->find('list'); 

會。 這裏是協會的代碼:

/** 
* belongsTo associations 
* 
* @var array 
*/ 
public $belongsTo = array(
    'Programs' => array(
     'className' => 'Programs', 
     'foreignKey' => 'Programs_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ), 
    'Etats' => array(
     'className' => 'Etats', 
     'foreignKey' => 'Etats_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ), 
    'Types' => array(
     'className' => 'Types', 
     'foreignKey' => 'Types_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ), 
    'ChampsLibres' => array(
     'className' => 'ChampsLibres', 
     'foreignKey' => 'Champs_libres_id', 
     'conditions' => '', 
     'fields' => '', 
     'order' => '' 
    ), 


); 
+0

一些關聯被刪除,因爲stackoverflow想要更少的代碼。 – 2012-07-13 19:31:02

+4

和你的問題是什麼? – pollirrata 2012-07-13 19:38:37

回答

1

仔細看你的代碼:

public $belongsTo = array(
'Programs' => array(
    'className' => 'Programs', 
    'foreignKey' => 'Programs_id', 
    'conditions' => '', 
    'fields' => '', 
    'order' => '' 
), 

無論對於關聯和類名的別名是多元的,而這是可能的罰款,它違背了CakePHP的約定。您正在嘗試這樣的:

$programs = $this->Chantier->Program->find('list'); 

但請注意,您在奇異寫程序而不是複數在協會的聲明。我建議重新烘焙你的代碼以遵循約定來避免未來的頭痛和混亂。