src/Controller/DeathCertificateController.php line 104

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\DeathCertificate;
  4. use App\Form\DeathCertificateType;
  5. use App\Repository\DeathCertificateRepository;
  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. use App\Form\TestType;
  11. /**
  12. * @Route("/death/certificate")
  13. */
  14. class DeathCertificateController extends AbstractController
  15. {
  16. /**
  17. * @Route("/", name="death_certificate_index", methods={"GET"})
  18. */
  19. public function index(DeathCertificateRepository $deathCertificateRepository): Response
  20. {
  21. return $this->render('death_certificate/index.html.twig', [
  22. 'death_certificates' => $deathCertificateRepository->findAll(),
  23. ]);
  24. }
  25. /**
  26. * @Route("/new", name="death_certificate_new", methods={"GET","POST"})
  27. */
  28. public function new(Request $request): Response
  29. {
  30. $deathCertificate = new DeathCertificate();
  31. $form = $this->createForm(DeathCertificateType::class, $deathCertificate);
  32. $form->handleRequest($request);
  33. if ($form->isSubmitted() && $form->isValid()) {
  34. $entityManager = $this->getDoctrine()->getManager();
  35. $entityManager->persist($deathCertificate);
  36. $entityManager->flush();
  37. return $this->redirectToRoute('death_certificate_index');
  38. }
  39. return $this->render('death_certificate/new.html.twig', [
  40. 'death_certificate' => $deathCertificate,
  41. 'form' => $form->createView(),
  42. ]);
  43. }
  44. /**
  45. * @Route("/complete_death", name="death_test", methods={"GET","POST"})
  46. */
  47. public function test(Request $request){
  48. $form = $this->createForm(TestType::class);
  49. $form->handleRequest($request);
  50. if ($form->isSubmitted() && $form->isValid()) {
  51. $id = $form['id']->getData();
  52. $val = intval($id);
  53. return $this->redirectToRoute('death_certificate_edit', [
  54. 'id' => $val
  55. ]);
  56. }
  57. return $this->render('test/new.html.twig',[
  58. 'form'=>$form->createView()
  59. ]
  60. );
  61. }
  62. /**
  63. * @Route("/{id}", name="death_certificate_show", methods={"GET"})
  64. */
  65. public function show(DeathCertificate $deathCertificate): Response
  66. {
  67. return $this->render('death_certificate/show.html.twig', [
  68. 'death_certificate' => $deathCertificate,
  69. ]);
  70. }
  71. /**
  72. * @Route("/{id}/edit", name="death_certificate_edit", methods={"GET","POST"})
  73. */
  74. public function edit(Request $request, DeathCertificate $deathCertificate): Response
  75. {
  76. $form = $this->createForm(DeathCertificateType::class, $deathCertificate);
  77. $form->handleRequest($request);
  78. if ($form->isSubmitted() && $form->isValid()) {
  79. $this->getDoctrine()->getManager()->flush();
  80. return $this->redirectToRoute('death_certificate_index');
  81. }
  82. return $this->render('death_certificate/edit.html.twig', [
  83. 'death_certificate' => $deathCertificate,
  84. 'form' => $form->createView(),
  85. ]);
  86. }
  87. /**
  88. * @Route("/{id}", name="death_certificate_delete", methods={"DELETE"})
  89. */
  90. public function delete(Request $request, DeathCertificate $deathCertificate): Response
  91. {
  92. if ($this->isCsrfTokenValid('delete'.$deathCertificate->getId(), $request->request->get('_token'))) {
  93. $entityManager = $this->getDoctrine()->getManager();
  94. $entityManager->remove($deathCertificate);
  95. $entityManager->flush();
  96. }
  97. return $this->redirectToRoute('death_certificate_index');
  98. }
  99. }