src/Controller/SeanceDetailController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Seance;
  4. use App\Entity\SeanceDetail;
  5. use App\Form\SeanceDetailType;
  6. use App\Repository\SeanceDetailRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. #[Route('/seance/detail')]
  12. class SeanceDetailController extends AbstractController
  13. {
  14.     #[Route('/new/{id}'name'app_seance_detail_new'methods: ['GET''POST'])]
  15.     public function new(Seance $seance,Request $requestSeanceDetailRepository $seanceDetailRepository): Response
  16.     {
  17.         $seanceDetail = new SeanceDetail();
  18.         $form $this->createForm(SeanceDetailType::class, $seanceDetail);
  19.         $form->handleRequest($request);
  20.         if ($form->isSubmitted() && $form->isValid()) {
  21.             $seanceDetail->setRefSeance($seance);
  22.             $seanceDetailRepository->add($seanceDetailtrue);
  23.             return $this->redirectToRoute('app_seance_show', ["id" => $seance->getId()], Response::HTTP_SEE_OTHER);
  24.         }
  25.         return $this->renderForm('seance_detail/new.html.twig', [
  26.             'seance' => $seance,
  27.             'seance_detail' => $seanceDetail,
  28.             'form' => $form,
  29.         ]);
  30.     }
  31.     #[Route('/{id}/edit'name'app_seance_detail_edit'methods: ['GET''POST'])]
  32.     public function edit(Request $requestSeanceDetail $seanceDetailSeanceDetailRepository $seanceDetailRepository): Response
  33.     {
  34.         $form $this->createForm(SeanceDetailType::class, $seanceDetail);
  35.         $form->handleRequest($request);
  36.         if ($form->isSubmitted() && $form->isValid()) {
  37.             $seanceDetailRepository->add($seanceDetailtrue);
  38.             return $this->redirectToRoute('app_seance_show', ["id" => $seanceDetail->getRefSeance()->getId()], Response::HTTP_SEE_OTHER);
  39.         }
  40.         return $this->renderForm('seance_detail/edit.html.twig', [
  41.             'seance_detail' => $seanceDetail,
  42.             'form' => $form,
  43.         ]);
  44.     }
  45.     #[Route('/{id}'name'app_seance_detail_delete'methods: ['POST'])]
  46.     public function delete(Request $requestSeanceDetail $seanceDetailSeanceDetailRepository $seanceDetailRepository): Response
  47.     {
  48.         if ($this->isCsrfTokenValid('delete'.$seanceDetail->getId(), $request->request->get('_token'))) {
  49.             $seanceDetailRepository->remove($seanceDetailtrue);
  50.         }
  51.         return $this->redirectToRoute('app_seance_detail_index', [], Response::HTTP_SEE_OTHER);
  52.     }
  53. }