【发布时间】:2011-09-24 18:49:54
【问题描述】:
我在 CakePHP 应用中有 2 个表被点赞,一个是拥有一个 Profile 喜欢的用户。
在创建新用户时,我已经设法自动在两者中创建条目,但是,当我尝试在我的用户编辑页面中编辑所有内容时,它会创建一个新的个人资料条目,导致我的用户有 2 个个人资料链接到.
两个模型都完美编码和链接,正如我所说,我能够创建一个新用户,系统会自动创建配置文件并链接它。
这是我的 user_controller.php 的编辑功能无法正常工作:
函数编辑($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid User', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->User->save($this->data)) {
$this->data['Profile']['user_id'] = $this->User->id;
$this->User->Profile->保存($this->data);
$this->Session->setFlash(__('用户保存', true));
$this->redirect(array('action' => 'index'));
} 别的 {
$this->Session->setFlash(__('无法保存用户。请重试。', true));
}
}
如果(空($this->data)){
$this->data = $this->User->read(null, $id);
}
}
非常感谢您的帮助!
【问题讨论】:
标签: php mysql cakephp cakephp-1.3