Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Customize Flash message in Cakephp 2

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 745
    Comment on it

    Customize Flash message in Cakephp 2

    If you want to customize flash message, and want to integrate your own alert flash box, then you can do this by SessionComponent method.


    Step 1 : First of all you need to include the session component.


    public $components = array('Session');


    Step 2: Now in the second step we will create custom_flash.ctp file in Elements folder located in cakephp_project/app/View/Elements/

    In this file, you can put your own alert box flash html in the following way:


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

    Now save this custom_flash.ctp file.


    Step 3: Now in the third step we will call the method SetFlash in controller. You can see the source code for it.


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


    As you can see that the second parameter is used for calling view element, so here you will call custom_flash in the following way:


    $this->Session->setFlash(__('Your message.'), 'custom_flash');


    Now save your controller and now perform action in order to get this flash message:


    Thanks for reading the blog.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: