在一个动作中,我为用户设置了一些反馈:
$this->getUser()->setFlash('message', array(
"type" => "notice",
"content" => "Well done buddy, you did it."
));
$this->redirect('home/index');
在视图中,我只使用以下代码:
<?php if ($sf_user->hasFlash('message')): $message = $sf_user->getFlash('message') ?>
<p class="<?php echo $message["type"] ?>" ><?php echo $message["content"]?></p>
<?php endif; ?>
但该消息从未出现。
并不是说问题不是“它出现一次然后消失”,因为这意味着它可以工作。问题是它永远不会出现。不止一次。
我使用的是 Symfony 1.2,这就是为什么 flash var 现在绑定到用户对象的原因。