From 7b12f109891b7aab412320fb3adb2f04b2334a4e Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Mon, 25 Nov 2024 20:45:16 -0500 Subject: [PATCH] Add some documenation and pull the session interface out once. --- app/src/Middlewares.php | 6 ++++-- app/templates/layouts/components/flash.twig | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/Middlewares.php b/app/src/Middlewares.php index 9501d25..721a2c9 100644 --- a/app/src/Middlewares.php +++ b/app/src/Middlewares.php @@ -16,6 +16,7 @@ use Twig\Error\LoaderError; class Middlewares { /** + * @param App $app The Slim application * @throws NotFoundExceptionInterface * @throws ContainerExceptionInterface * @throws LoaderError @@ -46,9 +47,10 @@ class Middlewares $twig->getEnvironment()->addGlobal('site_name', $config->get('site.name')); $twig->getEnvironment()->addGlobal('site_description', $config->get('site.description')); - $flash = $container->get(SessionInterface::class)->getFlash(); + $session = $container->get(SessionInterface::class); + $flash = $session->getFlash(); + $twig->getEnvironment()->addGlobal('session', $session); $twig->getEnvironment()->addGlobal('flash', $flash); - $twig->getEnvironment()->addGlobal('session', $container->get(SessionInterface::class)); $app->add(TwigMiddleware::create($app, $twig)); diff --git a/app/templates/layouts/components/flash.twig b/app/templates/layouts/components/flash.twig index fa1989d..d4497d6 100644 --- a/app/templates/layouts/components/flash.twig +++ b/app/templates/layouts/components/flash.twig @@ -10,10 +10,6 @@ {% endfor %} -{% if flash.has('error') %} -
Hello!
-{% endif %} - {% for message in flash.get('error') %}
{{ message }}