Session setFlash() vs Controller flash()

I was a bit confused when i suddenly came across controller::flash() recently. That made me research a little bit and here it goes.
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).

setFlash($message, $layout = 'default', $params = array(), $key = 'flash');

  • $message – Message to be flashed (required).
  • $layout – Layout to wrap flash message in.
  • $params – Parameters to be sent to layout as view variables. Additional params below can be passed to customize the output, or the Message.
  • $key – Message key, default is ‘flash’.

If you leave the $layout set to default it will wrap the message as follows:
$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.
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);

  • $message – Message to display to the user (required).
  • $url – Relative string or array-based URL to redirect to after the time expires.
  • $pause – Time to show the message (default 1 sec).
  • $layout – Layout you want to use, defaults to ‘flash’.

For in-page flash messages, use SessionComponent’s setFlash() method.