Posts Tagged ‘setflash’

CakePHP 1.2 Flash Usage

Friday, February 1st, 2008

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.