src/Controller/CronController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Cron;
  4. use App\Form\CronType;
  5. use App\Repository\CronRepository;
  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. #[Route('/cron')]
  11. class CronController extends AbstractController
  12. {
  13.     #[Route('/'name'app_cron_index'methods: ['GET'])]
  14.     public function index(CronRepository $cronRepository): Response
  15.     {
  16.         return $this->render('cron/index.html.twig', [
  17.             'crons' => $cronRepository->findAll(),
  18.         ]);
  19.     }
  20.     #[Route('/new'name'app_cron_new'methods: ['GET''POST'])]
  21.     public function new(Request $requestCronRepository $cronRepository): Response
  22.     {
  23.         $cron = new Cron();
  24.         $form $this->createForm(CronType::class, $cron);
  25.         $form->handleRequest($request);
  26.         if ($form->isSubmitted() && $form->isValid()) {
  27.             $cron->setAuthor($this->getUser()->getEmail());
  28.             $cronRepository->add($cron);
  29.             return $this->redirectToRoute('app_main', [], Response::HTTP_SEE_OTHER);
  30.         }
  31.         return $this->renderForm('cron/new.html.twig', [
  32.             'cron' => $cron,
  33.             'form' => $form,
  34.         ]);
  35.     }
  36.     #[Route('/{id}'name'app_cron_show'methods: ['GET'])]
  37.     public function show(Cron $cron): Response
  38.     {
  39.         return $this->render('cron/show.html.twig', [
  40.             'cron' => $cron,
  41.         ]);
  42.     }
  43.     #[Route('/{id}/edit'name'app_cron_edit'methods: ['GET''POST'])]
  44.     public function edit(Request $requestCron $cronCronRepository $cronRepository): Response
  45.     {
  46.         $form $this->createForm(CronType::class, $cron);
  47.         $form->handleRequest($request);
  48.         if ($form->isSubmitted() && $form->isValid()) {
  49.             $cronRepository->add($cron);
  50.             return $this->redirectToRoute('app_cron_index', [], Response::HTTP_SEE_OTHER);
  51.         }
  52.         return $this->renderForm('cron/edit.html.twig', [
  53.             'cron' => $cron,
  54.             'form' => $form,
  55.         ]);
  56.     }
  57.     #[Route('/{id}'name'app_cron_delete'methods: ['POST'])]
  58.     public function delete(Request $requestCron $cronCronRepository $cronRepository): Response
  59.     {
  60.         if ($this->isCsrfTokenValid('delete'.$cron->getId(), $request->request->get('_token'))) {
  61.             $cronRepository->remove($cron);
  62.         }
  63.         return $this->redirectToRoute('app_cron_index', [], Response::HTTP_SEE_OTHER);
  64.     }
  65. }