. . .

Working with flash messages in Yii

Published: September 22, 2010

On This Page

    If you would like to inform the user, that his changes were successfully saved, you could add the following line to your Controller:

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

     

    Displaying the flash message in a view is done by

    if( Yii::app()->user->hasFlash('success') ) {
        echo Yii::app()->user->getFlash('success');
    }

     

    If you want the flash message to automatically fade out after a few seconds, you will have to add the following lines to your view:

    Yii::app()->clientScript->registerScript(
    			    'myHideEffect',
    			    '$("div[class^=flash-]").animate({opacity: 1.0}, 3000).fadeOut("slow");',
    			    CClientScript::POS_READY
    			);

     

    Don't forget to share this post

      Let's Build Digital Excellence Together


      • Cost Efficient Solutions.
      • Minimal Timelines.
      • Effective Communication.
      • High Quality Standards.
      • Lifetime Support.
      • Transparent Execution.
      • 24/7 Availability.
      • Scalable Teams.

      Join Our 200+ Happy Clients Across Globe


      Free Consultation.

        Do you need tech help of your startup/business? Experts from our team will get in touch with you.

        Please do not post jobs/internships inquiries here.