【发布时间】:2012-03-19 21:39:22
【问题描述】:
现在,这种情况并不总是发生,我复制错误的努力已经失败了。
基本上,我们有一个工作系统,其中包含用户、标题、正文和截止日期。有时,从作业的编辑表单中保存会产生重复,即相同的作业(具有所有相同的内容)但具有新的 ID。
我想知道是否有人遇到过类似的错误。
这是我的 Job Controller 的编辑功能:
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid job', true));
}
if (!empty($this->data)) {
if ($this->Job->save($this->data)) {
$this->Session->setFlash(__('The job has been saved', true));
} else {
$this->Session->setFlash(__('The job could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Job->read(null, $id);
}
$users = $this->Job->User->find('list', array('fields' => array('User.username')));
$clients = $this->Job->Client->find('list');
$stages = $this->Job->Stage->find('list');
$this->set(compact('users', 'clients', 'stages'));
}
感谢任何帮助。
【问题讨论】:
-
当你说重复时,你的意思是右边和一个新条目都被保存了,还是右边条目没有更新,而是创建了一个副本?
-
记录的id是否总是存在于$this->data中?
-
@G.J 是正确的。下面的答案一针见血!
标签: cakephp controller cakephp-1.3 save