Yii Setflash For Displaying Messages ( Fade Out Message)

------------- In controller file ------

public function actionRegister()

{

if($model->save()){





    Yii::app()->user->setFlash('register','Success - College Registration');


    $this->refresh();








}

}

------------- In View, register.php ------

<?php

#Load jQuery file

Yii::app()->clientScript->registerCoreScript(‘jquery’);

?>

<style>

div.flash-success{text-align: center;margin-top: 10px;color: #FFF; margin-left: 5px;border: 1px solid #ccc;background-color: #44ae04; padding-left: 10px; -moz-border-radius: 5px;  -webkit-border-radius: 5px; -khtml-border-radius: 5px;border-radius: 5px;}

</style>

<?php if(Yii::app()->user->hasFlash(‘register’)): ?>

&lt;div class=&quot;flash-success&quot;&gt;


    &lt;?php echo Yii::app()-&gt;user-&gt;getFlash('register'); ?&gt;


&lt;/div&gt;

<?php endif; ?>

<script type="text/javascript">

$(document).ready(function(){$(".flash-success").fadeOut(5000);});

</script>

Hope it works…

[size="2"]You can also use below Yii code in view file,[/size]


<?php if(Yii::app()->user->hasFlash('register')):?>

	<div class="flash-error">

		<?php echo Yii::app()->user->getFlash('register'); ?>

		<?php

		Yii::app()->clientScript->registerScript(

		'myHideEffect',

		'$(".flash-error").animate({opacity: 1.0}, 5000).fadeOut("slow");',

		CClientScript::POS_READY

);

	?>

	</div>

<?php endif; ?>

Thank you kiran…

For Success message use success div instead of error div,

<div class="flash-success">

I tried with your code (for Success message)

But, message is not fading out.

Please check my code…

<?php if(Yii::app()->user->hasFlash(‘register’)): ?>

<div class="flash-success">

<?php echo Yii::app()->user->getFlash(‘register’); ?>

<?php

	Yii::app()-&gt;clientScript-&gt;registerScript(


	'myHideEffect',


	'&#036;(&quot;.flash-success&quot;).animate({opacity: 1.0}, 5000).fadeOut(&quot;slow&quot;);',


	CClientScript::POS_READY);


    ?&gt;

</div>

<?php endif; ?>

[/size]

[size="2"]Use below code in View:[/size]




<?php if(Yii::app()->user->hasFlash('success')):?>

	<div class="flash-success">

		<?php echo Yii::app()->user->getFlash('success'); ?>

		<?php

		

		Yii::app()->clientScript->registerScript(

		'myHideEffect',

		'$(".flash-success").animate({opacity: 1.0}, 3000).fadeOut("slow");',

		CClientScript::POS_READY

);

		?>

	</div>

<?php endif; ?>

Use below code in controller to set flash:


Yii::app()->user->setFlash('success', "Thank you for contacting us. We will respond to you as soon as possible.");

And make sure that if your page is customized page (not yii core page and with customize layout) main.css must be included.

if its not included you can include using below code,




$baseUrl = Yii::app()->baseUrl; 

$cs = Yii::app()->getClientScript();

$cs->registerCssFile($baseUrl.'/css/main.css');