From d1ffe814cc4d61189f6e65be9284e6a334197cd1 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Sat, 25 May 2024 22:23:53 -0400 Subject: [PATCH] Add Flash messages, set the sessions to the storage during request. --- app/src/Bootstrap.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/Bootstrap.php b/app/src/Bootstrap.php index 0c6fe0e..ee0442c 100644 --- a/app/src/Bootstrap.php +++ b/app/src/Bootstrap.php @@ -55,7 +55,10 @@ class Bootstrap $containerBuilder->addDefinitions([ 'config' => $config, // more DI stuff - + 'flash' => function () { + $messages = []; + return new \Slim\Flash\Messages($messages); + } ]); return $containerBuilder->build(); @@ -99,6 +102,16 @@ class Bootstrap ->addGlobal('site_description', $config->get('site.description')); $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); + }); } /**