user327712
user327712

Reputation: 3321

$session->flash()

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?

Upvotes: 2

Views: 4970

Answers (4)

Indrajeet Singh
Indrajeet Singh

Reputation: 2989

In view section for show messages.
$this->Session->flash();

Upvotes: 0

Muhammad Zohaib Yunis
Muhammad Zohaib Yunis

Reputation: 536

For latest cakephp version
if(!($this->Session->check('Message.flash')));
// your code

Upvotes: 0

Leo
Leo

Reputation: 6571

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.

Upvotes: 1

user196106
user196106

Reputation:

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.

Upvotes: 7

Related Questions