Yii 1.1: simple-flash-message

Simple Flash Message is a widget for render web user flash messages with auto hide effect using JQuery.


Yii 1.1 or above


To set up the widget, download and extract under protected/components folder.

To render the widget for all view, you need to add the following code snippet to your main layout, place it between breadcrumbs and content:

        <?php if(isset($this->breadcrumbs)):?>
        <?php $this->widget('zii.widgets.CBreadcrumbs', array(
        )); ?><!-- breadcrumbs -->
    <?php endif?>
    // this is the widget
    <?php $this->widget('Flashes'); ?>
    <?php echo $content; ?>

Example usage in controller: Just like using original setFlash Yii function. Types of messages that can be used is 'success', 'error', and 'notice'.

        public function actionUpdate($id)
                // here is the code to set flash message
                    Yii::app()->user->setFlash('success','Save data successfully');
                    $this->redirect(array('view', 'id'=>$model->id));

Total 1 comment

#6715 report it
Jgsaw at 2012/01/31 10:03am
Basic but useful

Not a huge gain but as a page load performance gain I would move the if ($flashMessages) check up above the register JS part as theres no point registering the JS if there are no flashes. I aslo made style configurable if desired (although possibly overkill) i.e.

$flashMessages = Yii::app()->user->getFlashes();
    if ($flashMessages) {
       '$(".flashes").animate({opacity: 0.9}, 3500).fadeOut("slow");',
    echo '<div class="flashes" style="'.$this->style.'">';
    foreach($flashMessages as $key => $message) {
        echo '<div class="flash-' . $key . ' shadow">' . $message . "</div>\n";
    echo '</div>';
public $style = 'text-align:center; padding:5px 20px 0px 20px';

Leave a comment

Please to leave your comment.

Create extension