src/Controller/HospitalController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Hospital;
  4. use App\Form\HospitalType;
  5. use App\Repository\HospitalRepository;
  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("/hospital")
  12. */
  13. class HospitalController extends AbstractController
  14. {
  15. /**
  16. * @Route("/", name="hospital_index", methods={"GET"})
  17. */
  18. public function index(HospitalRepository $hospitalRepository): Response
  19. {
  20. return $this->render('hospital/index.html_1.twig', [
  21. 'hospitals' => $hospitalRepository->findAll(),
  22. ]);
  23. }
  24. /**
  25. * @Route("/new", name="hospital_new", methods={"GET","POST"})
  26. */
  27. public function new(Request $request): Response
  28. {
  29. $hospital = new Hospital();
  30. $form = $this->createForm(HospitalType::class, $hospital);
  31. $form->handleRequest($request);
  32. if ($form->isSubmitted() && $form->isValid()) {
  33. $entityManager = $this->getDoctrine()->getManager();
  34. $entityManager->persist($hospital);
  35. $entityManager->flush();
  36. return $this->redirectToRoute('hospital_index');
  37. }
  38. return $this->render('hospital/new.html.twig', [
  39. 'hospital' => $hospital,
  40. 'form' => $form->createView(),
  41. ]);
  42. }
  43. /**
  44. * @Route("/{id}", name="hospital_show", methods={"GET"})
  45. */
  46. public function show(Hospital $hospital): Response
  47. {
  48. return $this->render('hospital/show.html_1.twig', [
  49. 'hospital' => $hospital,
  50. ]);
  51. }
  52. /**
  53. * @Route("/{id}/edit", name="hospital_edit", methods={"GET","POST"})
  54. */
  55. public function edit(Request $request, Hospital $hospital): Response
  56. {
  57. $form = $this->createForm(HospitalType::class, $hospital);
  58. $form->handleRequest($request);
  59. if ($form->isSubmitted() && $form->isValid()) {
  60. $this->getDoctrine()->getManager()->flush();
  61. return $this->redirectToRoute('hospital_index');
  62. }
  63. return $this->render('hospital/edit.html.twig', [
  64. 'hospital' => $hospital,
  65. 'form' => $form->createView(),
  66. ]);
  67. }
  68. /**
  69. * @Route("/{id}", name="hospital_delete", methods={"DELETE"})
  70. */
  71. public function delete(Request $request, Hospital $hospital): Response
  72. {
  73. if ($this->isCsrfTokenValid('delete'.$hospital->getId(), $request->request->get('_token'))) {
  74. $entityManager = $this->getDoctrine()->getManager();
  75. $entityManager->remove($hospital);
  76. $entityManager->flush();
  77. }
  78. return $this->redirectToRoute('hospital_index');
  79. }
  80. }