hzl-toastr Toastr, can use both in view and control, can fetch flashes set by you before, msg can show with user defined html format.

  1. Requirements
  2. Usage
  3. Result
  4. Resource

Toastr, can use in view and control, can fetch flashes message from controller, can show link in msg info, can show several same msgs type in single file:)

This is Scott Huang(zhiliang)'s 2nd widget extention:) First is hzl-googlechart. I also include into the zip to save your time.

Leverage Toastr 2.0.1 which published at Nov 1,2013


requirements of using this extension (e.g. Yii 1.1 or above)


1. Simple, will use type info and warning, normally write in view file, actually also can write in controller:)

$this->widget('ext.Hzl.toastr.HzlToastr', array(
            'message' => 'Please enter at least one condition to avoid huge output, thanks.',

        $this->widget('ext.Hzl.toastr.HzlToastr', array(
            'message' => 'A warning msg test :)',
            'title'=> 'test title',
           'type'=>'warning',  //info,success,warning,error

2. More option usage, write in view file

$this->widget('ext.Hzl.toastr.HzlToastr', array(
            'flashMessagesOnly'=> false, //default to false
            // msg will be ignore if flashMessagesOnly set to false
            'title' =>'Enhanced Usage Title',
            'message' => '<div><input class="input-small" value="textbox"/>&nbsp;<a href="http://johnpapa.net" target="_blank">This is a hyperlink</a></div><div><button type="button" id="okBtn" class="btn btn-primary">Close me</button><button type="button" id="surpriseBtn" class="btn" style="margin: 0 8px 0 8px">Surprise me</button></div>',
            //'message' => time().'temp adskfasdf',
            'type' => 'info',
            //the options passed to the plugin
            'options' => array(
                "closeButton" => true,
                "debug" => true,
                "positionClass" => "toast-top-right",
                "showDuration" => "300",
                "hideDuration" => "1000",
                "timeOut" => "15000",
                "extendedTimeOut" => "1000",
                "showEasing" => "swing",
                "hideEasing" => "linear",
                "showMethod" => "fadeIn",
                "hideMethod" => "fadeOut"

3. Enhanced usage with flash, normally set flash in controller, and get flash from view

a. In controller
//set some msg
            //Type will identify by title words, such as type will set by Success if title include success/Success word
                    Yii::app()->user->setFlash('No this Type', 'my test2: The model was saved with success');
                    Yii::app()->user->setFlash('Success:  Contact: ', 'Thank you for contacting us. We will respond to you as soon as possible.');
                    Yii::app()->user->setFlash('error', 'my test: The model was saved with success');

b. call message in view     
            $this->widget('ext.Hzl.toastr.HzlToastr', array(
                'flashMessagesOnly' => true, //default to false.  True will fetch setFlashes data
                'options' => array(
                    'timeOut' => 8000,

Add: I usually define one common func in component folder and call it easily.

public static function setMsg($title = '', $msg = '') {
        //yii::app()->user->setFlash(str_replace(array("'", '"'), array('`', '\"'), $title), str_replace(array("'", '"'), array('`', '\"'), $msg));
        yii::app()->user->setFlash(str_replace(array("'"), array('`'), $title), str_replace(array("'"), array('`'), $msg));


HzlToastr Result


Toastr Live Demo

3 0
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: Scott_Huang
Created on: Jan 2, 2014
Last updated: 8 years ago


show all

Related Extensions