I was a bit confused when i suddenly came across controller::flash() recently. That made me research a little bit and here it goes.
Session::setFlash()
It is used to set a session variable that can be used for output in the Views. You can have as many layouts at (/app/views/layouts).
Syntax
setFlash($message, $layout = 'default', $params = array(), $key = 'flash');
If you leave the $layout set to default it will wrap the message as follows:
[message]
$params allows you to pass additional view variables to the rendered layout. $key sets the $messages index in the Message array. Default is ‘flash’.
Parameters can be passed affecting the rendered div, for example padding “class” in the $params array will apply a class to the div output using $session->flash() in your layout or view.
$this->Session->setFlash('Example message text', 'default', array('class' => 'example_class'));
The output from using $session->flash() with the above example would be:
Example message text
Using a Custom Layout /app/views/layouts/success.ctp
$this->Session->setFlash('Example message text', 'flash_success', array('class' => 'success'));
would output
Example message text
The main thing. Use the following code to make the flash message where you want it to appear. Dont forget to use this in your layout.
$session->flash();
Controller::flash()
Like redirect(), the flash() method is used to direct a user to a new page after an operation. The flash() method is different in that it shows a message before passing the user on to another URL. Uses flash.ctp as the default layout for the message. Does not work if the current debug level is higher than 0. In development modes, you have to click on the flash message to continue.
flash(string $message, string $url, integer $pause);
For in-page flash messages, use SessionComponent’s setFlash() method.