所以如果我的Forward
模型中有以下验证规则
public $validate = array(
'url' =>array(
'rule' => 'url',
'message' => 'Please supply a valid Url.'
)
);
我想在flash中显示消息我该如何实现?
我尝试了以下内容:
$new_forward = $this->request->data;
$this->Forward->create();
$this->Session->setFlash($this->Forward->save($new_forward));
还尝试了这个没有结果
$this->Session->setFlash($this->ModelName->validationErrors);
答案 0 :(得分:1)
您可以使用以下示例代码
执行此操作$this->Forward->create();
if ($this->Forward->save($this->request->data))
{
$this->Session->setFlash(__('The Forward has been saved', true),'flash_success');
$this->redirect(array('controller' => 'forwards','action' => 'index'));
}
else
{
$this->Session->setFlash(__('The Forward could not be saved. Please, try again.', true),'flash_error');
}