因此,驗證錯誤顯示在我的添加動作中,但不在我的編輯動作中。下面是我的控制器中的片段:CakePHP:爲什麼不驗證錯誤顯示?
在這裏,我得到驗證錯誤消息的預期:
public function add() {
if ($this->request->is('post')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved.'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please try again.'));
}
}
$this->set('clients', $this->User->Client->find('list'));
}
但不是在這裏:
public function edit($id = null) {
$this->User->id = $id;
if (!$this->User->exists()) {
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.'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
} else {
$this->request->data = $this->User->read(null, $id);
unset($this->request->data['User']['password']);
}
$this->set('user', $this->User->read());
$this->set('clients', $this->User->Client->find('list'));
}
錯字:如果($這個 - >用戶 - >保存($這個 - >請求 - >數據/)) - 額外/末 – RichardAtHome 2012-04-16 13:18:51
啊,我的原始代碼中有一條評論,我刪除了SO。 – 2012-04-16 13:21:02