现在,这并非一直发生,我的复制错误的努力已被击中和错过。CakePHP - 在编辑记录时,有时会得到重复的
基本上,我们有一个工作制度,有一个用户,一个标题,正文和截止日期。有时,从作业的编辑表格中保存会产生重复的,即相同的作业(具有所有相同的内容),但具有新的编号。
我想知道是否有人遇到类似的错误。
这是我的工作控制器的编辑功能:
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'));
}
任何帮助表示赞赏。
当你说重复,你的意思是,右侧和新的条目都保存或正确的条目不更新,并创建一个副本? – 2012-03-01 12:12:43
记录的ID是否总是出现在$ this-> data中? – mark 2012-03-01 12:14:54
@ G.J,这是正确的。下面的答案击中了头部! – 2012-03-01 14:48:12