sabersma
flash
内容存储在session
中, 和debug module
没什么关系.addFlash('a', 'b')
之后, 再getFlash('a')
之后, 是可以销毁这条消息.但是 : 是在下次请求中销毁, 本次请求的后续处理中还存在.
@sabersma 其实也就是setFlash()参数
$removeAfterAccess = true (delete after access) or false (delete until the next call)
两种情况下的自动销毁没有生效,但是其他方式的显式删除flash是可以的。(第四个case == 第一个case, 忽略它吧)是别的地方有什么需要配置吗?
flash
内容存储在session
中, 和debug module
没什么关系.addFlash('a', 'b')
之后, 再getFlash('a')
之后, 是可以销毁这条消息.但是 : 是在下次请求中销毁, 本次请求的后续处理中还存在.
@500miles
额,不好意思我记错了,getFlash()时置delete=true 或是调用$session->removeFlash()都是有效的。但是除此之外的自动销毁还是无效。刚才写了下测试:
actions:public function actionTestFlash() { Yii::$app->session->setFlash('delete when access', 'hello world', true); Yii::$app->session->setFlash('delete when next call', 'hello world', false); Yii::$app->session->setFlash('set delete when getFlash', 'hello world'); Yii::$app->session->setFlash('set nothing, wait for auto delete in the next call', 'hello world'); } public function actionNewCall1() { return $this->render('new_call1'); } public function actionNewCall2() { return $this->render('new_call2'); }
new_call1.php:
$session = Yii::$app->session; var_dump('delete when access' . ' - ' . $session->getFlash('delete when access')); var_dump('delete when next call' . ' - ' . $session->getFlash('delete when next call')); var_dump('set delete when getFlash' . ' - ' . $session->getFlash('set delete when getFlash', null, true)); var_dump('set nothing, wait for auto delete in the next call' . ' - ' . $session->getFlash('set nothing, wait for auto delete in the next call')); var_dump($_SESSION);
new_call2.php:
$session = Yii::$app->session; $flashes = $session->getAllFlashes(); var_dump($flashes); var_dump($_SESSION); $session->removeAllFlashes();
new-call1的输出:
string(32) "delete when access - hello world" string(35) "delete when next call - hello world" string(38) "set delete when getFlash - hello world" string(64) "set nothing, wait for auto delete in the next call - hello world" array(4) { ["delete when access"]=> string(11) "hello world" ["__flash"]=> array(3) { ["delete when access"]=> int(1) ["delete when next call"]=> int(0) ["set nothing, wait for auto delete in the next call"]=> int(1) } ["delete when next call"]=> string(11) "hello world" ["set nothing, wait for auto delete in the next call"]=> string(11) "hello world" }
new_call2输出:
array(3) { ["delete when access"]=> string(11) "hello world" ["delete when next call"]=> string(11) "hello world" ["set nothing, wait for auto delete in the next call"]=> string(11) "hello world" } array(4) { ["delete when access"]=> string(11) "hello world" ["__flash"]=> array(3) { ["delete when access"]=> int(1) ["delete when next call"]=> int(0) ["set nothing, wait for auto delete in the next call"]=> int(1) } ["delete when next call"]=> string(11) "hello world" ["set nothing, wait for auto delete in the next call"]=> string(11) "hello world" }
除了在getFlash()时设置delete=true的那次之外其余三次均没有正常销毁,当然,removeAllFlashes()之后整个世界都清净了。
- sabersma 2015-11-25 已签到连续签到2天,获得了10个金钱
- sabersma 2015-11-24 已签到连续签到1天,获得了5个金钱