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.











February 9th, 2008 at 4:36 am
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 !
June 21st, 2008 at 12:15 am
Ohhh!!!! Thankyou very much!!!!!!
June 21st, 2008 at 12:17 am
you can add that :
var $helpers = array(’Session’);
in controller.