dmstr\widgets\Alert::init PHP Метод

init() публичный Метод

This method will register the bootstrap asset bundle. If you override this method, make sure you call the parent implementation first.
public init ( )
    public function init()
    {
        parent::init();
        $session = \Yii::$app->getSession();
        $flashes = $session->getAllFlashes();
        $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
        foreach ($flashes as $type => $data) {
            if (isset($this->alertTypes[$type])) {
                $data = (array) $data;
                foreach ($data as $message) {
                    $this->options['class'] = $this->alertTypes[$type]['class'] . $appendCss;
                    $this->options['id'] = $this->getId() . '-' . $type;
                    echo BootstrapAlert::widget(['body' => $this->alertTypes[$type]['icon'] . $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
                }
                if ($this->isAjaxRemoveFlash && !\Yii::$app->request->isAjax) {
                    $session->removeFlash($type);
                }
            }
        }
    }

Usage Example

Пример #1
0
 /**
  * Initializes the widget.
  * This method will register the bootstrap asset bundle. If you override this method,
  * make sure you call the parent implementation first.
  */
 public function init()
 {
     parent::init();
     $session = Yii::$app->getSession();
     $flashes = $session->getAllFlashes();
     $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
     foreach ($flashes as $type => $data) {
         if (isset($this->alertTypes[$type])) {
             $data = (array) $data;
             foreach ($data as $message) {
                 $this->options['class'] = $this->alertTypes[$type]['class'] . $appendCss;
                 $this->options['id'] = $this->getId() . '-' . $type;
                 echo BootstrapAlert::widget(['body' => $this->alertTypes[$type]['icon'] . $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
             }
             //$session->removeFlash($type);
         }
     }
 }
Alert