Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP customize flash message

Normally, the $this->Session->setFlash(__('My message.'));

Will output:

<div id="flashMessage" class="message">
    My message.
</div>

How can I change that, so it'll output:

<p class="notification>
    My message.
</p>

instead?

like image 846
Cyclone Avatar asked Nov 03 '11 05:11

Cyclone


1 Answers

If you look at the source code you will see that the second parameter of the SessionComponent method is the name of an element:

function setFlash($message, $element = 'default', $params = array(), $key = 'flash')

You can create a file in views/elements (or Views/Elements for Cake2) called for instance 'flash_notification.ctp'

with the following content:

<p class="notification">
  <?php echo $message; ?>
</p>

and use

$this->Session->setFlash(__('My message.'), 'flash_notification');
like image 165
nIcO Avatar answered Sep 24 '22 15:09

nIcO