芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/xmintal-back/widgets/Alert.php
session->setFlash('error', 'This is the message'); * Yii::$app->session->setFlash('success', 'This is the message'); * Yii::$app->session->setFlash('info', 'This is the message'); * ``` * * Multiple messages could be set as follows: * * ```php * Yii::$app->session->setFlash('error', ['Error 1', 'Error 2']); * ``` * * @author Kartik Visweswaran
* @author Alexander Makarov
*/ class Alert extends \yii\bootstrap4\Widget { /** * @var array the alert types configuration for the flash messages. * This array is setup as $key => $value, where: * - key: the name of the session flash variable * - value: the bootstrap alert type (i.e. danger, success, info, warning) */ public $alertTypes = [ 'error' => 'alert-danger', 'danger' => 'alert-danger', 'success' => 'alert-success', 'info' => 'alert-info', 'warning' => 'alert-warning' ]; /** * @var array the options for rendering the close button tag. * Array will be passed to [[\yii\bootstrap\Alert::closeButton]]. */ public $closeButton = []; /** * {@inheritdoc} */ public function run() { $session = Yii::$app->session; $appendClass = isset($this->options['class']) ? ' ' . $this->options['class'] : ''; foreach (array_keys($this->alertTypes) as $type) { $flash = $session->getFlash($type); foreach ((array) $flash as $i => $message) { echo \yii\bootstrap4\Alert::widget([ 'body' => $message, 'closeButton' => $this->closeButton, 'options' => array_merge($this->options, [ 'id' => $this->getId() . '-' . $type . '-' . $i, 'class' => $this->alertTypes[$type] . $appendClass, ]), ]); } $session->removeFlash($type); } } }