From 9dfd212718dfbdd4a3379566e0fa14fb8d443d94 Mon Sep 17 00:00:00 2001 From: bayard Date: Thu, 17 Oct 2024 17:53:18 +0200 Subject: [PATCH] push de controller cuisinier /add /delete --- src/Controller/CuisinierController.php | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Controller/CuisinierController.php diff --git a/src/Controller/CuisinierController.php b/src/Controller/CuisinierController.php new file mode 100644 index 0000000..c2097ea --- /dev/null +++ b/src/Controller/CuisinierController.php @@ -0,0 +1,46 @@ +createForm(CuisinierType::class, $cuisinier); + + $form->handleRequest($request); + if ($form->isSubmitted() && $form->isValid()) { + $entityManager->persist($cuisinier); + $entityManager->flush(); + + $this->addFlash('success', 'Cuisinier ajouté avec succès !'); + return $this->redirectToRoute('ajouter_cuisinier'); + } + + return $this->render('cuisinier/ajouter.html.twig', [ + 'form' => $form->createView(), + ]); + } + + #[Route('/cuisinier/supprimer/{id}', name: 'supprimer_cuisinier', methods: ['POST'])] + public function supprimer(int $id, EntityManagerInterface $entityManager): Response + { + $cuisinier = $entityManager->getRepository(Cuisinier::class)->find($id); + + if (!$cuisinier) { + throw $this->createNotFoundException('Ce cuisinier n\'existe pas'); + } + + $entityManager->remove($cuisinier); + $entityManager->flush(); + + $this->addFlash('success', 'Cuisinier supprimé avec succès !'); + return $this->redirectToRoute('ajouter_cuisinier'); + } +} \ No newline at end of file