PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 18, 2022

[FIXED] CakePHP customize flash message

 January 18, 2022     cakephp, customization, message     No comments   

Issue

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?


Solution

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');


Answered By - nIcO
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing