当我使用Tree行为并脚手架我的控制器时,我的parent_id显示在添加视图的选择框中;但是,当我烘焙我的控制器和视图时,我最终得到了一个空的父选择框。我知道这很简单,但我无法弄明白。
这是我的控制器:
public function add() {
if ($this->request->is('post')) {
$this->Test->create();
if ($this->Test->save($this->request->data)) {
$this->Session->setFlash(__('The test has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The test could not be saved. Please, try again.'));
}
}
$parentTests = $this->Test->ParentTest->find('list');
$this->set(compact('parentTests'));
}
这是我的模特:
public $belongsTo = array(
'ParentTest' => array(
'className' => 'Test',
'foreignKey' => 'parent_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public $hasMany = array(
'ChildTest' => array(
'className' => 'Test',
'foreignKey' => 'parent_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
如果有人能帮助我解决这个问题,我将不胜感激。提前谢谢。
答案 0 :(得分:0)
烘焙可能无法正确解决问题。
您必须手动调整它,将变量重命名为parents
:
$parents = $this->Test->ParentTest->find('list');
$this->set(compact('parents'));