我在保存编辑的数据时遇到错误。实际上用户点击了编辑按钮用户被重定向到编辑数据页面最后(之后)当用户想要保存编辑的数据时编辑数据 cakephp 给出错误 sql 完整性违规代码 1062。编辑代码是由生成的默认代码蛋糕烘烤。代码是
public function edit($id = null) {
if (!$this->User->exists($id)) {
throw new NotFoundException(__('Invalid user'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
$this->request->data = $this->User->find('first', $options);
}
}
我也尝试了保存字段而不是保存,但这是添加所有空字段的新用户。