【发布时间】:2018-03-06 16:00:03
【问题描述】:
关于 cakephp 项目。我有 2 个模型
<?php class VisaPerson extends AppModel {
public $name = 'VisaPerson';
public $primaryKey = 'id';}?>
和
<?php class VisaProcess extends AppModel {
public $name = 'VisaProcess';
public $primaryKey = 'id';
public $belongsTo = array(
'VisaPerson' => array (
'className' => 'VisaPerson',
'foreignKey' => 'people_id'
)
);
}
?>
在控制器中,我写道:
if ($this->request->is('post')) {
if (!empty($this->request->data)) {
$person = $this->VisaPerson->save($this->request->data);
if (!empty($person)) {
$this->request->data['VisaProcess']['people_id'] = $this->$person->id;
$this->VisaPerson->VisaProcess->save($this->request->data);
}
}
数据保存在 VisaPerson 但 VisaProcess people_id 不自动保存。 请帮帮我!
【问题讨论】:
-
请阅读有关保存关联的内容,您在此处所做的操作是不必要且容易出错的,CakePHP 可以开箱即用地处理保存关联:book.cakephp.org/2.0/en/models/saving-your-data.html
标签: php cakephp associations cakephp-2.x