src/Controller/FormationsController.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Formations;
  4. use App\Form\FormationsType;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. class FormationsController extends AbstractController
  11. {
  12.     public function __construct(EntityManagerInterface $manager){
  13.         $this->manager $manager;
  14.     }
  15.     /**
  16.      * @Route("/admin/formations", name="app_formations")
  17.      */
  18.     public function index(Request $request): Response
  19.     {
  20.         $formations = new Formations(); // Nouvelle instance de user (il hérite des propriétés du user)
  21.         $form $this->createForm(FormationsType::class, $formations); // Création du formulaire
  22.         $form->handleRequest($request); // Traitement du formulaire
  23.         if($form->isSubmitted() && $form->isValid()) { // Si le formulaire est soumis et validé alors..
  24.             
  25.             $this->manager->persist($formations); // On persister l'utilisateur (cela signifie elle prépare l'envoie des données)
  26.             $this->manager->flush(); // On flush
  27.             return $this->redirectToRoute('app_home'); // on redirige vers la page de connexion
  28.         }
  29.         
  30.         return $this->render('formations/index.html.twig', [
  31.             'myForm' => $form->createView() // On passe le formulaire à la vue, je pointe vers la fonction createView
  32.         ]);
  33.     }
  34.     
  35.     /**
  36.      * @Route("/all/formations", name="app_all_formations")
  37.      */
  38.     public function affichage(): Response
  39.     {
  40.         $allformations $this->manager->getRepository(Formations::class)->findAll();
  41.         return $this->render('formations/allformations.html.twig', [
  42.             'Formations' => $allformations,
  43.         ]);
  44.     }
  45.      /**
  46.      * @Route("/admin/delete/formations{id}", name="app_admin_delete_formations")
  47.      */
  48.     public function delete(Formations $formations): Response
  49.     {
  50.        $this->manager->remove($formations);
  51.        $this->manager->flush();
  52.        return $this->redirectToRoute('app_all_formations');
  53.     }
  54.      /**
  55.      * @Route("/admin/edit/formations{id}", name="app_admin_edit_formations")
  56.      */
  57.     public function Edit(Formations $formationsRequest $request): Response
  58.     {
  59.        
  60.         $form $this->createForm(FormationsType::class, $formations); // Création du formulaire
  61.         $form->handleRequest($request); // Traitement du formulaire
  62.         if($form->isSubmitted() && $form->isValid()) { // Si le formulaire est soumis et validé alors..
  63.             
  64.             $this->manager->persist($formations); // On persister l'utilisateur (cela signifie elle prépare l'envoie des données)
  65.             $this->manager->flush(); // On flush
  66.             return $this->redirectToRoute('app_all_formations'); // on redirige vers la page de connexion
  67.         }
  68.         
  69.         return $this->render('formations/edit.html.twig', [
  70.             'myForm' => $form->createView() // On passe le formulaire à la vue, je pointe vers la fonction createView
  71.         ]);
  72.     }
  73. }