Home » » success & error message in cakephp

success & error message in cakephp

Written By 1 on Monday, September 5, 2011 | 8:42 PM

Success & error message in cakephp.




The flash method uses the default key set by setFlash(). You can also retrieve specific keys in the session. For example, the Auth component sets all of its Session messages under the 'auth' key




In some web sites, particularly administration backoffice web applications it is often expected that the result of an operation requested by the user has associated feedback as to whether the operation succeeded or not. This is a classic usage for the flash mechanism since we only want to show the user the result once and not keep the message.
One way to achieve this is to use Session->flash() with the layout parameter. With the layout parameter we can be in control of the resultant html for the message.


Follow the following steps to set messages
 1) set the message and class name in controller
    <?php $this->Session->setFlash('Example message text', 'default', array('class' => 'msg')); ?>

2) in view or place where you want to display the message add the following line

    <?php $session->flash(); ?>

    It will render following code

   <div id="flashMessage" class="message"> Example message text</div>

0 Comment:

Post a Comment