src/Controller/TraningsController.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Tranings;
  4. use App\Form\TraningsType;
  5. use App\Repository\TraningsRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * @Route("/formations")
  13.  */
  14. class TraningsController extends AbstractController {
  15.     /**
  16.      * @Route("/", name="app_tranings_index", methods={"GET"})
  17.      */
  18.     public function index(TraningsRepository $traningsRepository): Response {
  19.         return $this->render('tranings/index.html.twig', [
  20.                     'tranings' => $traningsRepository->findAll(),
  21.         ]);
  22.     }
  23.     /**
  24.      * @Route("/new", name="app_tranings_new", methods={"GET", "POST"})
  25.      */
  26.     public function new(Request $request, TraningsRepository $traningsRepository): Response {
  27.         $traning = new Tranings();
  28.         $form = $this->createForm(TraningsType::class, $traning);
  29.         $form->handleRequest($request);
  30.         if ($form->isSubmitted() && $form->isValid()) {
  31.             $traningsRepository->add($traning);
  32.             return $this->redirectToRoute('app_tranings_index', [], Response::HTTP_SEE_OTHER);
  33.         }
  34.         return $this->renderForm('tranings/new.html.twig', [
  35.                     'traning' => $traning,
  36.                     'form' => $form,
  37.         ]);
  38.     }
  39.     /**
  40.      * @Route("/{id}/{slug}", name="app_tranings_show", methods={"GET"}, requirements={"id"="\d+"})
  41.      */
  42.     public function show(Tranings $traning, TraningsRepository $traningRepo, $id, $slug = null): Response {
  43.         $article = $traningRepo->find($id);
  44.         if (!$article) {
  45.             throw new NotFoundHttpException();
  46.         }
  47. //        $cat = $article->getCategory()->getId() . '-' . $article->getCategory()->getSlug();
  48.         if ($article->getSlug() !== $slug ) {
  49.             return $this->redirectToRoute('article_show', [
  50.                         'id' => $id,
  51.                         'slug' => $article->getSlug(),
  52. //                        'category' => $cat
  53.             ]);
  54.         }
  55.         return $this->render('tranings/show.html.twig', [
  56.                     'traning' => $traning,
  57.         ]);
  58.     }
  59. //    /**
  60. //     * @Route("/{id}/edit", name="app_tranings_edit", methods={"GET", "POST"})
  61. //     */
  62. //    public function edit(Request $request, Tranings $traning, TraningsRepository $traningsRepository): Response {
  63. //        $form = $this->createForm(TraningsType::class, $traning);
  64. //        $form->handleRequest($request);
  65. //
  66. //        if ($form->isSubmitted() && $form->isValid()) {
  67. //            $traningsRepository->add($traning);
  68. //            return $this->redirectToRoute('app_tranings_index', [], Response::HTTP_SEE_OTHER);
  69. //        }
  70. //
  71. //        return $this->renderForm('tranings/edit.html.twig', [
  72. //                    'traning' => $traning,
  73. //                    'form' => $form,
  74. //        ]);
  75. //    }
  76. //    /**
  77. //     * @Route("/{id}", name="app_tranings_delete", methods={"POST"})
  78. //     */
  79. //    public function delete(Request $request, Tranings $traning, TraningsRepository $traningsRepository): Response {
  80. //        if ($this->isCsrfTokenValid('delete' . $traning->getId(), $request->request->get('_token'))) {
  81. //            $traningsRepository->remove($traning);
  82. //        }
  83. //
  84. //        return $this->redirectToRoute('app_tranings_index', [], Response::HTTP_SEE_OTHER);
  85. //    }
  86. }