CakePHP 1.2 Flash Usage
- At February 1, 2008
- By Aaron
- In CakePHP
6
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 parameter is the number of seconds before redirecting.


Patrice Lazareff
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 !
Dante
Ohhh!!!! Thankyou very much!!!!!!
Dante
you can add that :
var $helpers = array(‘Session’);
in controller.
Vince Delmonte
Hey, cool tips. Perhaps I’ll buy a bottle of beer to the person from that forum who told me to go to your site :)
Emerson
I’m in the process of trying out CakePHP, but have some solid experience with Ruby on Rails. Things seem much less polished with Cake so far, and this whole flash stuff has been really painful compared to the elegance of Rails. Either-way, your post has definitely helped me, so thanks for that!
Hopefully I’ll get my head around Cake soon enough…
Fahima D costa
Another short article today on something that took me some digging to learn.thanks. :)