src/Controller/BilanController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use DateTime;
  4. use App\Entity\Bilan;
  5. use DateTimeImmutable;
  6. use App\Form\BilanType;
  7. use App\Repository\BilanRepository;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. /**
  13.  * @Route("/bilan")
  14.  */
  15. class BilanController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/", name="app_bilan_index", methods={"GET"})
  19.      */
  20.     public function index(BilanRepository $bilanRepository): Response
  21.     {
  22.         return $this->render('bilan/index.html.twig', [
  23.             'bilans' => $bilanRepository->findAll(),
  24.         ]);
  25.     }
  26.     /**
  27.      * @Route("/new", name="app_bilan_new", methods={"GET", "POST"})
  28.      */
  29.     public function new(Request $requestBilanRepository $bilanRepository): Response
  30.     {
  31.         $bilan = new Bilan();
  32.         $form $this->createForm(BilanType::class, $bilan);
  33.         $form->handleRequest($request);
  34.         if ($form->isSubmitted() && $form->isValid()) {
  35.             $bilan->setCreatedAt(new  DateTimeImmutable());
  36.             $bilan->setUpdatedAt(new DateTimeImmutable());
  37.             $bilan->setActive(true);
  38.             $allergie $request->request->get('allergie');
  39.             $bilan->setAllergic($allergie);
  40.             
  41.             $bilanRepository->add($bilantrue);
  42.             return $this->redirectToRoute('app_bilan_show', ["id"=> $bilan->getId()]);
  43.         }
  44.         return $this->renderForm('bilan/new.html.twig', [
  45.             'bilan' => $bilan,
  46.             'form' => $form,
  47.         ]);
  48.     }
  49.     /**
  50.      * @Route("/{id}", name="app_bilan_show", methods={"GET"})
  51.      */
  52.     public function show(Bilan $bilan): Response
  53.     {
  54.         return $this->render('bilan/show.html.twig', [
  55.             'bilan' => $bilan,
  56.         ]);
  57.     }
  58.     /**
  59.      * @Route("/{id}/edit", name="app_bilan_edit", methods={"GET", "POST"})
  60.      */
  61.     public function edit(Request $requestBilan $bilanBilanRepository $bilanRepository): Response
  62.     {
  63.         $form $this->createForm(BilanType::class, $bilan);
  64.         $form->handleRequest($request);
  65.         if ($form->isSubmitted() && $form->isValid()) {
  66.             $bilanRepository->add($bilantrue);
  67.             return $this->redirectToRoute('app_bilan_index', [], Response::HTTP_SEE_OTHER);
  68.         }
  69.         return $this->renderForm('bilan/edit.html.twig', [
  70.             'bilan' => $bilan,
  71.             'form' => $form,
  72.         ]);
  73.     }
  74.     /**
  75.      * @Route("/{id}", name="app_bilan_delete", methods={"POST"})
  76.      */
  77.     public function delete(Request $requestBilan $bilanBilanRepository $bilanRepository): Response
  78.     {
  79.         if ($this->isCsrfTokenValid('delete'.$bilan->getId(), $request->request->get('_token'))) {
  80.             $bilanRepository->remove($bilantrue);
  81.         }
  82.         return $this->redirectToRoute('app_bilan_index', [], Response::HTTP_SEE_OTHER);
  83.     }
  84. }