Version:

Page Contents

FlashComponent provides a way to set one-time notification messages to be
displayed after processing a form or acknowledging data. CakePHP refers to these
messages as “flash messages”. FlashComponent writes flash messages to
$_SESSION, to be rendered in a View using
FlashHelper.

The FlashComponent replaces the setFlash() method on SessionComponent
and should be used instead of that method.

FlashComponent provides two ways to set flash messages: its __call
magic method and its set() method.

To use the default flash message handler, you can use the set()
method:

$this->Flash->set('This is a message');

New in version 2.10.0: Flash messages now stack. Successive calls to set() or __call() with
the same key will append the messages in the $_SESSION. If you want to
keep the old behavior (one message even after consecutive calls), set the
clear option to true when setting messages.

To create custom Flash elements, FlashComponent’s __call magic
method allows you use a method name that maps to an element located under
the app/View/Elements/Flash directory. By convention, camelcased
methods will map to the lowercased and underscored element name: