Tuesday, 6 September 2011

Success & Error message in cakephp1.3

Success & Error message in cakephp 1.3.

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(); ?>
  3. It will render following code
       <div id="flashMessage" class="message"> Example message text</div>