[SOLVED] Showing UserFlash only for some seconds

Hello!

In a Controller I am setting a user flash after saving some data:

Yii::app()->user->setFlash('success',"Data successfully saved!");

I am showing this in the view using



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


<div class="info">


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


</div>


<?php endif; ?>


Working good so far. Now my question: How can I make the flash message  showing up only for x seconds? I want it to hide automatically after x seconds using some effect. Before starting an extensive  "try and error" session, I wanted to ask, if someone could post a code snippet for that… :wink:

Thanks in advance

Thomas

Hi Thomas,

You can try for example:



<?php


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


	'myHideEffect', 


	'$(".info").fadeOut("slow");', 


	CClientScript::POS_READY


);


?>


for the effects, have a look at: http://docs.jquery.com/Effects

greets ironic

Hi ironic,

thank you for your answer! It made the div disappear, but without waiting a few seconds. I changed it a little biit, adding

.animate({opacity: 1.0}, 3000)

Now it's working, showing the div for 3 seconds and then fading it out:

<?php


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


   'myHideEffect',


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


   CClientScript::POS_READY


);


?>

greets

Thomas

You can use too javascript function:



setTimeout ( exp​ression, timeout );


Good job. Maybe put it into the cookbook?

Quote

Good job. Maybe put it into the cookbook?

I just created a new entry for that:

http://www.yiiframew…oc/cookbook/21/

Greets

Thomas

Nice writing! Thanks.