views:

49

answers:

2

Hi all,

I am using cakePHP v1.26. In the default.ctp file, I got a single of this code in it:

$session->flash();

I came a corss a web site in which the author suggested using this instead:

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

I do not understand what this line of code is doing:

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

what is "Message.flash" in this case? Is "Message.flash" a custom variable or
a built-in varibale which has been predefined in cakePHP?

+4  A: 

Message.flash is the session variable name. It will be defined by cakephp, when you use $this->Session->setFlash('Your message'); from your controller.

if($session->check('Message.flash')){...} checks, if session Message.flash, which contains the flash message, exists.

aRagnis
What is the standard usage of Message.flash?
paullb
CakePHP stores your flash message in it.
aRagnis
+1  A: 

Note also that contrary to the current manual description, $session->flash() does not echo the result, it just returns it, so you will need to have

echo $session->flash();

in your view.

Leo