Flashes in Yii

Flashes.php(widget)


Set Flash message:
Yii::app()->user->setFlash('success', t("user","message"));

check if contain Flash message :
if(Yii::app()->user->hasFlash('success'))

To show flash message(view file):
<?php $this->widget('Flashes'); ?>

Flash message only last for next page. If we want to after more than one page then have to RE-set flash message.

class Flashes extends CWidget {<br /> public function run() {<br /> Yii::app()->clientScript->registerScript('myHideEffect','$(" fadeout="" lientscript::pos_ready="" opacity:="" slow=""> $flashMessages = Yii::app()->user->getFlashes();
if ($flashMessages) {
 echo  '<div class="flashes" style="text-align:center; padding:5px 20px 0px 20px">';
foreach($flashMessages as $key => $message) {
        echo '<div class="flash-' . $key . ' shadow">' . $message."</div>\n";
}
echo '</div>';
 }
}}

Share this

Related Posts

Previous
Next Post »