0

so if i have the following validation rule in my Forward model

    public $validate = array(
    'url' =>array(
        'rule' => 'url',
        'message' => 'Please supply a valid Url.'
    )
);

and i want to display the message in a flash how do i achieve that?

I have tried the following:

        $new_forward = $this->request->data;
        $this->Forward->create();
        $this->Session->setFlash($this->Forward->save($new_forward));

Also tried this with no result

$this->Session->setFlash($this->ModelName->validationErrors);
4

1 回答 1

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');
}
于 2013-08-16T12:20:44.280 回答