我想保存在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