私は CakePHP が初めてで、いくつかのチュートリアルに従って簡単なフォームを作成しました。この html フォームでは、検証を使用しました。問題は、検証は機能していますが、メッセージに表示したいものが表示されないことです。以下のコードを試しました。
モデル
public $validate = array(
'title' => array(
'title_required' => array(
'rule' => 'notEmpty',
'message' => 'This is required field'
),
'title_unique' => array(
'rule' => 'isUnique',
'message' => 'This should be unique title'
)
)
);
コントローラ
public function add() {
if ($this->request->data) {
if ($this->Post->save($this->request->data)) {
$this->Session->setFlash('Post has been added successfully');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Error occured, Please try agan later!');
}
}
}
意見
<h2>Add New Post</h2>
<?php
echo $this->Form->create('Post', array('action'=>'add'));
echo $this->Form->input('title');
echo $this->Form->input('body');
echo $this->Form->end('Create Post');
?>
私が見た検証エラーは、コントローラーで言及したメッセージではありません。