我想保存在CakePHP 2.0相關的數據,在我有兩個表,表的實體(ID,main_name),並不會忽略(ID,ENTITY_ID,市)保存CakePHP的2.0協會
中的實體模型數據庫我所做的關聯關係:
public $hasMany = array(
'Address' => array(
'className' => 'Address',
'foreignKey' => 'entity_id'
)
);
在我保存了以下數據AdressesController:
public function add() {
if ($this->request->is('post')) {
if($this->Entity->save($this->request->data)) {
$this->Flash->success('Entity successfully registered!');
$this->redirect(array('action' => 'add'));
} else {
$this->Flash->error(Oops, we could not register this entity!
Make sure it already exists.');
}
}
}
並在視圖,我的形式如下:
<?php
echo $this->Form->input(
'Entity.main_name',
array(
'type' => 'text',
'class' => 'form-control',
'label' => false
)
);
?>
<?php
echo $this->Form->input(
'Address.city',
array(
'type' => 'text',
'class' => 'form-control',
'label' => false
)
);
?>
實體的數據通常保存在數據庫中,但與entity_id沒有關係,並且不會將城市保存在地址表中,是否必須在控制器中執行其他任何操作?
很好的解釋謝謝 – Henrique