Yii Framework Forum: Yii Setflash For Displaying Messages ( Fade Out Message) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Setflash For Displaying Messages ( Fade Out Message) Rate Topic: -----

#1 User is offline   Subrahmanyam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 27-July 13
  • Location:Hyderabad,India

Posted 14 August 2013 - 06:34 AM

------------- 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')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('register'); ?>
</div>
<?php endif; ?>

<script type="text/javascript">
$(document).ready(function(){$(".flash-success").fadeOut(5000);});
</script>


Hope it works...
Thanks,
B.N.Subrahmanyam ( Enjo(YII)ng...)
Sr.PHP Developer
0

#2 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 21-May 11
  • Location:India

Posted 14 August 2013 - 06:43 AM

View PostSubrahmanyam, on 14 August 2013 - 06:34 AM, said:

Replying to Yii Setflash For Displaying Messages ( Fade Out Message)

You can also use below Yii code in view file,

<?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; ?>

Thanks,
Kiran Sharma.
1

#3 User is offline   Subrahmanyam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 27-July 13
  • Location:Hyderabad,India

Posted 14 August 2013 - 06:45 AM

View Postkiran sharma, on 14 August 2013 - 06:43 AM, said:

You can also use below Yii code in view file,

<?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...
Thanks,
B.N.Subrahmanyam ( Enjo(YII)ng...)
Sr.PHP Developer
0

#4 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 21-May 11
  • Location:India

Posted 14 August 2013 - 06:51 AM

View PostSubrahmanyam, on 14 August 2013 - 06:45 AM, said:

Thank you kiran...


For Success message use success div instead of error div,

<div class="flash-success">
Thanks,
Kiran Sharma.
0

#5 User is offline   Subrahmanyam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 27-July 13
  • Location:Hyderabad,India

Posted 14 August 2013 - 07:00 AM

View Postkiran sharma, on 14 August 2013 - 06:51 AM, said:

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()->clientScript->registerScript(
'myHideEffect',
'$(".flash-success").animate({opacity: 1.0}, 5000).fadeOut("slow");',
CClientScript::POS_READY);
?>
</div>
<?php endif; ?>
Thanks,
B.N.Subrahmanyam ( Enjo(YII)ng...)
Sr.PHP Developer
0

#6 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 494
  • Joined: 21-May 11
  • Location:India

Posted 14 August 2013 - 07:34 AM

View PostSubrahmanyam, on 14 August 2013 - 07:00 AM, said:

message is not fading out.

Use below code in View:

<?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');

Thanks,
Kiran Sharma.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users