FlashWidget.php 1.09 KB
<?php
    namespace artbox\core\widgets;
    
    use yii\base\Widget;
    use Yii;

    /**
     * Class FleshWidget
     *
     * @package artbox\core\widgets
     */
    class FlashWidget extends Widget
    {
        public $flashes = [
            'success',
            'info',
            'warning',
            'error',
        ];
        
        public function run()
        {
            foreach ($this->flashes as $flash) {
                if (Yii::$app->session->hasFlash($flash)) {
                    $message = Yii::$app->session->getFlash($flash);
                    $js = '
                      new PNotify({
                        title: "' . Yii::t('core', 'Notification') . ':",
                        text: "' . $message . '",
                        type: "' . $flash . '",
                        styling: "bootstrap3",
                        icon: "glyphicon glyphicon-exclamation-sign"
                      });
                      ';
                    return $this->render('_flash', [ 'js' => $js ]);
                }
            }
            return '';
        }
    
    }