From 69ea47facd9b654d6ae4b81f43374b9b71a6e920 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 6 Sep 2018 19:41:46 +0200 Subject: [PATCH] Added messages --- application/src/Controller/UserController.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/application/src/Controller/UserController.php b/application/src/Controller/UserController.php index 065f906..1c87fe2 100644 --- a/application/src/Controller/UserController.php +++ b/application/src/Controller/UserController.php @@ -42,13 +42,19 @@ class UserController extends AbstractController implements UserControllerInterfa 'label' => 'register' ]) ->getForm(); - $form->handleRequest($request); + $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $task = $form->getData(); $entityManager = $this->getDoctrine()->getManager(); $entityManager->persist($task); - $entityManager->flush(); + try { + $entityManager->flush(); + $this->addFlash('success', 'User created!'); + } catch (\Exception $exception) { + $this->addFlash('danger', 'User could not be created!'); + $this->addFlash('info', $exception->getMessage()); + } + } return $this->render("user/register.html.twig", [ 'form' => $form->createView()