in my view, main.php
i have this
use yii\bootstrap4\Alert;
<?php
Alert::widget();
?>
and in my main.php
'session' => [
'class' => 'yii\web\DbSession',
'sessionTable' => 'session',
],
my seesion table look like this
CREATE TABLE `session` (
`id` char(40) NOT NULL,
`expire` int(11) NOT NULL,
`data` longblob NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
when i use yii\web\Session
in my main.php instead of yii\web\DbSession
flash works fine. But with DbSession i get this
<div id="w4" class="alert alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>
</div>
and it’s not using the proper Bootstrap 4 classes either. So i tried extending the alert class, to this
class Alert extends \yii\bootstrap4\Widget
{
public $alertTypes = [
'error' => 'alert-danger',
'danger' => 'alert-danger',
'success' => 'alert-success',
'info' => 'alert-info',
'warning' => 'alert-warning'
];
public $closeButton = [];
public function run()
{
$session = Yii::$app->session;
$flashes = $session->getAllFlashes();
$appendClass = isset($this->options['class']) ? ' ' . $this->options['class'] : '';
foreach ($flashes as $type => $flash) {
if (!isset($this->alertTypes[$type])) {
continue;
}
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);
}
}
}
but $session->getAllFlashes()
gives me an empty array.
Anyone know how to fix this? thanks