php yii-bootstrap-Alert类(方法)实例源码

下面列出了php yii-bootstrap-Alert 类(方法)源码代码实例,从而了解它的用法。

作者:alejandrosos    项目:A   
public function init()
 {
     parent::init();
     $session = \Yii::$app->session;
     $flashes = $session->getAllFlashes();
     $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
     foreach ($flashes as $type => $data) {
         //TOAST
         if (strpos($type, 'toast') !== false) {
             if (isset($this->toastTypes[$type])) {
                 $data = (array) $data;
                 foreach ($data as $i => $message) {
                     /* initialize css class for each alert box */
                     $tipo = $this->toastTypes[$type];
                     Toast::widget(['tipo' => $tipo, 'mensaje' => $message]);
                 }
                 $session->removeFlash($type);
             }
         } else {
             if (isset($this->alertTypes[$type])) {
                 $data = (array) $data;
                 foreach ($data as $i => $message) {
                     //echo '<pre>';print_r($i);die();
                     /* initialize css class for each alert box */
                     $this->options['class'] = $this->alertTypes[$type] . $appendCss;
                     /* assign unique id to each alert box */
                     $this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
                     echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
                 }
                 $session->removeFlash($type);
             }
         }
     }
 }

作者:radiegty    项目:easyi   
public function api_form()
 {
     $model = new GuestbookModel();
     $settings = Yii::$app->getModule('admin')->activeModules['guestbook']->settings;
     ob_start();
     $form = ActiveForm::begin(['enableClientValidation' => true, 'action' => Url::to(['/admin/guestbook/send'])]);
     switch (Yii::$app->session->getFlash(GuestbookModel::FLASH_KEY)) {
         case 'success':
             $message = Yii::$app->getModule('admin')->activeModules['guestbook']->settings['preModerate'] ? Yii::t('easyii/guestbook/api', 'Message successfully sent and will be published after moderation') : Yii::t('easyii/guestbook/api', 'Message successfully added');
             echo Alert::widget(['options' => ['class' => 'alert-success'], 'body' => $message]);
             break;
         case 'error':
             echo Alert::widget(['options' => ['class' => 'alert-danger'], 'body' => Yii::t('easyii/guestbook/api', 'An error has occurred')]);
             break;
     }
     echo $form->field($model, 'name');
     if ($settings['enableTitle']) {
         echo $form->field($model, 'title');
     }
     echo $form->field($model, 'text')->textarea();
     if ($settings['enableCaptcha']) {
         echo $form->field($model, 'reCaptcha')->widget(ReCaptcha::className());
     }
     echo Html::submitButton(Yii::t('easyii', 'Send'), ['class' => 'btn btn-primary']);
     ActiveForm::end();
     return ob_get_clean();
 }

作者:vladdnep    项目:yii2-yc   
/**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (Yii::$app instanceof Application) {
         $view = $this->getView();
         $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 $i => $message) {
                     /* initialize css class for each alert box */
                     $this->options['class'] = $this->alertTypes[$type] . $appendCss;
                     /* assign unique id to each alert box */
                     $this->options['id'] = $this->getId() . '-' . $type . '-' . $i;
                     echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
                     if ($this->delay > 0) {
                         $js = 'jQuery("#' . $this->options['id'] . '").fadeTo(' . $this->delay . ', 0.00, function() {
                             $(this).slideUp("slow", function() {
                                 $(this).remove();
                             });
                         });';
                         $view->registerJs($js);
                     }
                 }
                 $session->removeFlash($type);
             }
         }
     }
 }

作者:cakebak    项目:yii2-account   
public function init()
 {
     parent::init();
     $session = \Yii::$app->getSession();
     $flashes = $session->getAllFlashes();
     $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
     if (empty($flashes)) {
         return false;
     }
     foreach ($flashes as $type => $message) {
         //type check for more messages with the same type like "success-1"
         foreach ($this->alertTypes as $k => $t) {
             if (preg_match('/' . $k . '/', $type, $subpattern)) {
                 $type = $subpattern[0];
                 break;
             }
         }
         if (isset($this->alertTypes[$type])) {
             /* initialize css class for each alert box */
             $this->options['class'] = $this->alertTypes[$type] . $appendCss;
             /* assign unique id to each alert box */
             $this->options['id'] = $this->getId() . '-' . $type;
             echo '<div class="cakebake-accounts-alert">';
             echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
             echo '</div>';
             $session->removeFlash($type);
         }
     }
 }

作者:naveds    项目:yii2-advanced-templat   
/**
     * Initializes the widget.
     */
    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 $i => $message)
                {
                    /* initialize css class for each alert box */
                    $this->options['class'] = $this->alertTypes[$type] . $appendCss;

                    /* assign unique id to each alert box */
                    $this->options['id'] = $this->getId() . '-' . $type . '-' . $i;

                    echo \yii\bootstrap\Alert::widget([
                        'body' => $message,
                        'closeButton' => $this->closeButton,
                        'options' => $this->options,
                    ]);
                }

                $session->removeFlash($type);
            }
        }
    }

作者:maddoge    项目:yii2-admi   
public function run()
 {
     parent::init();
     $session = \Yii::$app->getSession();
     $flashes = $session->getAllFlashes();
     $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
     $alerts = '';
     foreach ($flashes as $type => $messages) {
         if (!isset($this->alertTypes[$type])) {
             /* initialize css class for each alert box */
             $type = self::FLASH_INFO;
         }
         if (!is_array($messages)) {
             $messages = [$messages];
         }
         foreach ($messages as $message) {
             $this->options['class'] = $this->alertTypes[$type] . $appendCss;
             /* assign unique id to each alert box */
             $this->options['id'] = $this->getId() . '-' . $type;
             $body = Html::tag('i', '', ['class' => 'fa fa-' . $this->alertIcons[$type]]) . $message;
             $alerts .= Alert::widget(['body' => $body, 'closeButton' => $this->closeButton, 'options' => $this->options]);
         }
         $session->removeFlash($type);
     }
     if ($alerts) {
         return strtr($this->template, ['{alerts}' => $alerts]);
     }
     return null;
 }

作者:RomarioLopez    项目:RobotS   
/**
  * Deletes an existing ProjectManager model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($user_id)
 {
     Yii::$app->db->createCommand()->delete('project_manager', 'user_id =' . $user_id . '')->execute();
     Yii::$app->db->createCommand()->delete('user', 'id =' . $user_id . '')->execute();
     echo Alert::widget(['body' => 'El usuario se eliminó exitosamente!']);
     return $this->redirect(['index']);
 }

作者:fnoorma    项目:de   
public function getAlert()
 {
     if ($this->success) {
         return Alert::widget(['options' => ['class' => 'alert-success'], 'body' => 'Congratulations!!! Your password has been changed...']);
     } else {
         return null;
     }
 }

作者:barie    项目:yii2-tool   
public function run()
 {
     $result = [];
     foreach (\Yii::$app->session->getAllFlashes() as $key => $message) {
         $result[] = \yii\bootstrap\Alert::widget(['options' => ['class' => 'alert-' . ($key == 'error' ? 'danger' : $key)], 'body' => implode("<hr />", (array) $message)]);
     }
     return implode('', $result);
 }

作者:loveorigam    项目:yii2-notification-wrappe   
/**
  * @param $options
  * @return string
  */
 public function getNotification($options)
 {
     $options['class'] = $this->alertTypes[$this->type]['class'];
     $msg = BootstrapAlert::widget(['body' => $this->alertTypes[$this->type]['icon'] . ' ' . $this->getMessageWithTitle(), 'options' => $options]);
     $msg = Json::encode($msg);
     $msg = trim($msg, '"');
     $id = $this->getLayerId();
     return "\$('#{$id}').append('{$msg}');";
 }

作者:zeleni    项目:yii2-widget   
/**
  * @inheritdoc
  */
 public function run()
 {
     foreach ($this->model->getErrors() as $attribute => $messages) {
         foreach ($messages as $key => $message) {
             $this->options['id'] = 'error-' . $attribute . '-' . $key;
             echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
         }
     }
 }

作者:zeleni    项目:yii2-widget   
/**
  * @inheritdoc
  */
 public function run()
 {
     $session = Yii::$app->getSession();
     foreach ($session->getAllFlashes() as $type => $message) {
         $this->options['class'] = ArrayHelper::getValue($this->alertTypes, $type, $this->alertTypes['info']);
         $this->options['id'] = $this->getId() . '-' . $type;
         echo \yii\bootstrap\Alert::widget(['body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
         $session->removeFlash($type);
     }
 }

作者:yiido    项目:yii2-flas   
public function run()
 {
     foreach ($this->getAlerts() as $alert) {
         if (isset($this->options['class'])) {
             Html::addCssClass($this->options, 'alert');
             Html::addCssClass($this->options, 'alert-' . $alert['type']);
         } else {
             $this->options['class'] = 'alert alert-' . $alert['type'];
         }
         echo \yii\bootstrap\Alert::widget(['closeButton' => $this->closeButton, 'options' => $this->options, 'body' => $alert['body']]);
     }
 }

作者:ahb36    项目:yii2-admin36   
public function run()
 {
     foreach (Yii::$app->session->getAllFlashes() as $type => $message) {
         if (!in_array($type, ['success', 'danger', 'error', 'warning', 'info'])) {
             $type = 'info';
         }
         $alertType = 'alert-' . $type;
         if (is_array($message)) {
             $message = array_pop($message);
         }
         echo Alert::widget(['options' => ['class' => "alert {$alertType} {$this->alertClass}"], 'body' => $message]);
     }
 }

作者:skeeks-cm    项目:cm   
/**
  * @inheritdoc
  */
 public function run()
 {
     try {
         if (!$this->hasModel()) {
             throw new Exception(\Yii::t('skeeks/cms', "Current widget works only in form with model"));
         }
         if ($this->model->isNewRecord) {
             throw new Exception(\Yii::t('skeeks/cms', "The image can be downloaded after you save the form data"));
         }
         echo $this->render('storage-image', ['model' => $this->model, 'widget' => $this]);
     } catch (\Exception $e) {
         echo Alert::widget(['options' => ['class' => 'alert-warning'], 'body' => $e->getMessage()]);
     }
 }

作者:manyoubaby12    项目:imsho   
public function init()
 {
     parent::init();
     $session = Yii::$app->getSession();
     $flashes = $session->getAllFlashes();
     $appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
     foreach ($flashes as $type => $message) {
         /* initialize css class for each alert box */
         $this->options['class'] = 'alert-' . $this->alertTypes[$type] . $appendCss;
         /* assign unique id to each alert box */
         $this->options['id'] = $this->getId() . '-' . $type;
         echo Alert::widget(['type' => $type, 'body' => $message, 'closeButton' => $this->closeButton, 'options' => $this->options]);
         $session->removeFlash($type);
     }
 }

作者:yiiste    项目:yii2-adminlt   
/**
  * @inheritdoc
  */
 public function run()
 {
     if (!isset($this->options['id'])) {
         $this->options['id'] = $this->getId();
     }
     echo Html::beginTag('div', $this->options);
     foreach ($this->flashes as $flashName => $alert) {
         if (Yii::$app->session->hasFlash($flashName)) {
             $header = '';
             if ($this->showHeader) {
                 $header = Html::tag('h4', (isset($alert['icon']) ? new Icon($alert['icon']) . '&nbsp;' : '') . $alert['header']);
             }
             echo Alert::widget(['body' => $header . Yii::$app->session->getFlash($flashName), 'options' => ['class' => 'alert alert-' . $alert['class']]]);
         }
     }
     echo Html::endTag('div');
 }

作者:albertborso    项目:yii2-li   
public static function showAlerts()
 {
     foreach (Yii::$app->getSession()->allFlashes as $type => $message) {
         switch ($type) {
             case 'error':
                 $type = 'danger';
                 break;
             default:
                 $exploded = explode('-', $type);
                 if (count($exploded) > 1) {
                     $type = $exploded[0];
                 }
                 break;
         }
         echo Alert::widget(['options' => ['class' => 'alert-' . $type], 'body' => $message]);
     }
 }

作者:Liv102    项目:cm   
/**
  * @inheritdoc
  */
 public function run()
 {
     try {
         if (!$this->hasModel()) {
             throw new Exception(\Yii::t('app', "Current widget works only in form with model"));
         }
         if ($this->model->isNewRecord) {
             throw new Exception(\Yii::t('app', "Images can be downloaded after you save the form data"));
         }
         if (!$this->model->hasProperty($this->attribute)) {
             throw new Exception("Relation {$this->attribute} не найдена");
         }
         echo $this->render('model-storage-files', ['model' => $this->model, 'widget' => $this]);
     } catch (\Exception $e) {
         echo Alert::widget(['options' => ['class' => 'alert-warning'], 'body' => $e->getMessage()]);
     }
 }

作者:airan    项目:yii2-adminlte-asse   
/**
  * 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);
         }
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号