1,Setting flash messages(设置)
A flash message is used in order to keep a message in session through one or several requests of the same user.
1 | Yii::app()->user->setFlash('success', "数据设置成功"); |
2,Displaying flash messages(显示)
To check for flash messages we use the hasFlash() Method and to obtain the flash message we use the getFlash() Method. Since Yii v1.1.3, there is also a method getFlashes() to fetch all the messages.
1),静态显示
1 | if(Yii::app()->user->hasFlash('success')): |
全部显示
1 | $flashMessages = Yii::app()->user->getFlashes(); |
2),动态显示
1 | Yii::app()->clientScript->registerScript( |
With these lines of code we register a piece of jQuery (already included with YII) javascript code, using ‘myHideEffect’ as ID. It will be inserted in the jQuery’s ready function (CClientScript::POS_READY).