Commit cca34951 by Alexander Makarov

Fixes #3979: Alert widget in advanced app is now able to display multiple flash…

Fixes #3979: Alert widget in advanced app is now able to display multiple flash messages of the same type
parent b12f4dd7
......@@ -11,9 +11,17 @@ namespace frontend\widgets;
* Alert widget renders a message from session flash. All flash messages are displayed
* in the sequence they were assigned using setFlash. You can set message as following:
*
* - \Yii::$app->getSession()->setFlash('error', 'This is the message');
* - \Yii::$app->getSession()->setFlash('success', 'This is the message');
* - \Yii::$app->getSession()->setFlash('info', 'This is the message');
* ```php
* \Yii::$app->getSession()->setFlash('error', 'This is the message');
* \Yii::$app->getSession()->setFlash('success', 'This is the message');
* \Yii::$app->getSession()->setFlash('info', 'This is the message');
* ```
*
* Multiple messages could be set as follows:
*
* ```php
* \Yii::$app->getSession()->setFlash('error', ['Error 1', 'Error 2']);
* ```
*
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @author Alexander Makarov <sam@rmcreative.ru>
......@@ -47,19 +55,22 @@ class Alert extends \yii\bootstrap\Widget
$flashes = $session->getAllFlashes();
$appendCss = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $message) {
foreach ($flashes as $type => $data) {
if (isset($this->alertTypes[$type])) {
/* initialize css class for each alert box */
$this->options['class'] = $this->alertTypes[$type] . $appendCss;
$data = (array) $data;
foreach ($data as $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;
/* assign unique id to each alert box */
$this->options['id'] = $this->getId() . '-' . $type;
echo \yii\bootstrap\Alert::widget([
'body' => $message,
'closeButton' => $this->closeButton,
'options' => $this->options,
]);
echo \yii\bootstrap\Alert::widget([
'body' => $message,
'closeButton' => $this->closeButton,
'options' => $this->options,
]);
}
$session->removeFlash($type);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment