src/Controller/EmpruntsController.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Emprunts;
  4. use App\Form\EmpruntsType;
  5. use App\Repository\EmpruntsRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route("/emprunts")
  12.  */
  13. class EmpruntsController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/", name="emprunts_index", methods={"GET"})
  17.      */
  18.     public function index(EmpruntsRepository $empruntsRepository): Response
  19.     {
  20.         return $this->render('emprunts/index.html.twig', [
  21.             'emprunts' => $empruntsRepository->findAll(),
  22.         ]);
  23.     }
  24.     /**
  25.      * @Route("/new", name="emprunts_new", methods={"GET","POST"})
  26.      */
  27.     public function new(Request $request): Response
  28.     {
  29.         $emprunt = new Emprunts();
  30.         $form $this->createForm(EmpruntsType::class, $emprunt);
  31.         $form->handleRequest($request);
  32.         if ($form->isSubmitted() && $form->isValid()) {
  33.             $entityManager $this->getDoctrine()->getManager();
  34.             $entityManager->persist($emprunt);
  35.             $entityManager->flush();
  36.             return $this->redirectToRoute('emprunts_index', [], Response::HTTP_SEE_OTHER);
  37.         }
  38.         return $this->renderForm('emprunts/new.html.twig', [
  39.             'emprunt' => $emprunt,
  40.             'form' => $form,
  41.         ]);
  42.     }
  43.     /**
  44.      * @Route("/{id}", name="emprunts_show", methods={"GET"})
  45.      */
  46.     public function show(Emprunts $emprunt): Response
  47.     {
  48.         return $this->render('emprunts/show.html.twig', [
  49.             'emprunt' => $emprunt,
  50.         ]);
  51.     }
  52.     /**
  53.      * @Route("/{id}/edit", name="emprunts_edit", methods={"GET","POST"})
  54.      */
  55.     public function edit(Request $requestEmprunts $emprunt): Response
  56.     {
  57.         $form $this->createForm(EmpruntsType::class, $emprunt);
  58.         $form->handleRequest($request);
  59.         if ($form->isSubmitted() && $form->isValid()) {
  60.             $this->getDoctrine()->getManager()->flush();
  61.             return $this->redirectToRoute('emprunts_index', [], Response::HTTP_SEE_OTHER);
  62.         }
  63.         return $this->renderForm('emprunts/edit.html.twig', [
  64.             'emprunt' => $emprunt,
  65.             'form' => $form,
  66.         ]);
  67.     }
  68.     /**
  69.      * @Route("/{id}", name="emprunts_delete", methods={"POST"})
  70.      */
  71.     public function delete(Request $requestEmprunts $emprunt): Response
  72.     {
  73.         if ($this->isCsrfTokenValid('delete'.$emprunt->getId(), $request->request->get('_token'))) {
  74.             $entityManager $this->getDoctrine()->getManager();
  75.             $entityManager->remove($emprunt);
  76.             $entityManager->flush();
  77.         }
  78.         return $this->redirectToRoute('emprunts_index', [], Response::HTTP_SEE_OTHER);
  79.     }
  80. }