2

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

4 回答 4

7

Message.flash是会话变量名称。$this->Session->setFlash('Your message');当您从控制器使用时,它将由 cakephp 定义。

if($session->check('Message.flash')){...}Message.flash检查是否存在包含 flash 消息的session 。

于 2010-06-20T18:40:45.150 回答
1

另请注意,与当前的手动描述相反, $session->flash() 不会显结果,它只是返回它,因此您需要

echo $session->flash();

在你看来。

于 2010-06-21T09:27:18.030 回答
0
In view section for show messages.
$this->Session->flash();
于 2014-04-30T05:51:46.540 回答
0

对于最新的 cakephp 版本
if(!($this->Session->check('Message.flash')));
// 你的代码

于 2013-09-04T13:17:18.927 回答