src/Controller/StatusController.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Status;
  4. use App\Form\StatusType;
  5. use App\Repository\StatusRepository;
  6. use Doctrine\ORM\EntityManagerInterface;
  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('/status')]
  12. class StatusController extends AbstractController
  13. {
  14.     #[Route('/'name'app_status_index'methods: ['GET'])]
  15.     public function index(StatusRepository $statusRepository): Response
  16.     {
  17.         return $this->render('status/index.html.twig', [
  18.             'statuses' => $statusRepository->findAll(),
  19.         ]);
  20.     }
  21.     #[Route('/new'name'app_status_new'methods: ['GET''POST'])]
  22.     public function new(Request $requestEntityManagerInterface $entityManager): Response
  23.     {
  24.         $status = new Status();
  25.         $form $this->createForm(StatusType::class, $status);
  26.         $form->handleRequest($request);
  27.         if ($form->isSubmitted() && $form->isValid()) {
  28.             $entityManager->persist($status);
  29.             $entityManager->flush();
  30.             return $this->redirectToRoute('app_status_index', [], Response::HTTP_SEE_OTHER);
  31.         }
  32.         return $this->renderForm('status/new.html.twig', [
  33.             'status' => $status,
  34.             'form' => $form,
  35.         ]);
  36.     }
  37.     #[Route('/{id}'name'app_status_show'methods: ['GET'])]
  38.     public function show(Status $status): Response
  39.     {
  40.         return $this->render('status/show.html.twig', [
  41.             'status' => $status,
  42.         ]);
  43.     }
  44.     #[Route('/{id}/edit'name'app_status_edit'methods: ['GET''POST'])]
  45.     public function edit(Request $requestStatus $statusEntityManagerInterface $entityManager): Response
  46.     {
  47.         $form $this->createForm(StatusType::class, $status);
  48.         $form->handleRequest($request);
  49.         if ($form->isSubmitted() && $form->isValid()) {
  50.             $entityManager->flush();
  51.             return $this->redirectToRoute('app_status_index', [], Response::HTTP_SEE_OTHER);
  52.         }
  53.         return $this->renderForm('status/edit.html.twig', [
  54.             'status' => $status,
  55.             'form' => $form,
  56.         ]);
  57.     }
  58.     #[Route('/{id}'name'app_status_delete'methods: ['POST'])]
  59.     public function delete(Request $requestStatus $statusEntityManagerInterface $entityManager): Response
  60.     {
  61.         if ($this->isCsrfTokenValid('delete'.$status->getId(), $request->request->get('_token'))) {
  62.             $entityManager->remove($status);
  63.             $entityManager->flush();
  64.         }
  65.         return $this->redirectToRoute('app_status_index', [], Response::HTTP_SEE_OTHER);
  66.     }
  67. }