pfth
(Pfth)
March 5, 2009, 8:36am
1
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…
Thanks in advance
Thomas
ironic
(Chaotikum)
March 5, 2009, 8:56am
2
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
pfth
(Pfth)
March 5, 2009, 9:40am
3
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
qwerty
(qwerty)
March 5, 2009, 11:23am
4
You can use too javascript function:
setTimeout ( expression, timeout );
qiang
(Qiang Xue)
March 5, 2009, 11:54am
5
Good job. Maybe put it into the cookbook?
pfth
(Pfth)
March 5, 2009, 6:54pm
6
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