YII框架中的Flash消息 [英] Flash Message in YII Framework
问题描述
在我发送请求后,我会通过SET FLASH向用户公布结果.用户发送请求时显示消息的方式是什么?
After I send the request, I will announce the result to the user via SET FLASH. What is the way to show a message when the user sends a request?
例如发送消息表单时:显示 -> 正在发送表单,然后显示一条闪现消息
For example when sending a message form : Display -> form is being send and then a flash message is displayed
推荐答案
查看 Yii 框架网站上的 wiki:http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/
Check the wiki on the Yii framework website: http://www.yiiframework.com/wiki/21/how-to-work-with-flash-messages/
在您的控制器中,您可以输入:
In your controller you can put:
Yii::app()->user->setFlash('success', "Form posted!");
在您看来,您可以通过以下方式回显闪消息:
In your view you can echo the flash message by:
<?php echo Yii::app()->user->getFlash('success'); ?>
或者,您可以使用 hasFlash 方法检查 Flash 消息是否存在,因此您视图中的代码如下所示:
Optionally you can check if a flash message exists by using the hasFlash method, so the code in your view would look like this:
<?php if(Yii::app()->user->hasFlash('success')):?>
<?php echo Yii::app()->user->getFlash('success'); ?>
<?php endif; ?>
这篇关于YII框架中的Flash消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!