CakePHP 1.2 Flash Usage

Another short article today on something that took me some digging (but not as much as usual!) to learn. You see mention of setFlash() all the time when
looking for CakePHP info. Until now I never knew how to implement the view side of this properly. He is the simple example (the kind I like the best) for using flash.

controller:

$this->Session->setFlash('your email is coming');

view:

if ($session->check('Message.flash')) {
  $session->flash();
}

Note: You do not have to include Session in your component list in your controller for this to work. Also, you may want to place the $session->flash() code in your layout instead of in various views.

Happy Cake’n

UPDATE

It was not clear to me how to use the flash method, but here it is:

$this->flash(’The animal has been modified.’, ‘/find_a_pet/search’, 3);

The first parameter is the message.

The second parameter is the url to redirect the user.

The third paramete is the number of seconds before redirecting.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • NewsVine
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • TwitThis
  • YahooMyWeb

Tags: , , , , ,

3 Responses to “CakePHP 1.2 Flash Usage”

  1. Patrice Lazareff Says:

    A related thing which also took me a (shorter than usual as well) while to get, is the way to display the Auth->loginError message in a login form. The key used is not the default ‘Flash’ but ‘Auth’, hence the code to put in the form:
    check(’Message.auth’)) $session->flash(’auth’); ?>

    VoilĂ … happy coding !

  2. Dante Says:

    Ohhh!!!! Thankyou very much!!!!!!

  3. Dante Says:

    you can add that :
    var $helpers = array(’Session’);

    in controller.

Leave a Reply