いつも忘れるのでメモ
Validationのエラーは$model->validationErrors
に入っている
http://api.cakephp.org/2.4/class-Model.html#$validationErrors
<?php
class UsersController extends AppController {
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$msg = __('The user has been saved.' );
$this->Session->setFlash($msg);
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user data could not be saved. Please, try again.'));
// validationエラーをログに残す
$this->log("validationErrors=" . var_export($this->User->validationErrors, true));
}
}
}
}