Add Flash messages, set the sessions to the storage during request.

This commit is contained in:
Dave Smith-Hayes 2024-05-25 22:23:53 -04:00
parent 7967f325fa
commit d1ffe814cc

View File

@ -55,7 +55,10 @@ class Bootstrap
$containerBuilder->addDefinitions([ $containerBuilder->addDefinitions([
'config' => $config, 'config' => $config,
// more DI stuff // more DI stuff
'flash' => function () {
$messages = [];
return new \Slim\Flash\Messages($messages);
}
]); ]);
return $containerBuilder->build(); return $containerBuilder->build();
@ -99,6 +102,16 @@ class Bootstrap
->addGlobal('site_description', $config->get('site.description')); ->addGlobal('site_description', $config->get('site.description'));
$app->add(TwigMiddleware::create($app, $twig)); $app->add(TwigMiddleware::create($app, $twig));
// Flash Messages
$app->add(function ($req, $next) {
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
$this->get('flash')->__construct($_SESSION);
return $next->handle($req);
});
} }
/** /**