src/Controller/FormationsController.php line 78

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Formations;
  4. use App\Form\FormationType;
  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\Component\String\Slugger\SluggerInterface;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. class FormationsController extends AbstractController
  12. {
  13.     public function __construct(EntityManagerInterface $manager){
  14.         
  15.         $this->manager $manager
  16.     }
  17.     
  18.         // *************************AFFICHAGE AJOUT FORMATIONS
  19.     
  20.         /**
  21.          * @Route("/admin/formation/ajout", name="app_formations_ajout")
  22.          */
  23.         public function formationAjout(Request $request): Response 
  24.         {
  25.             $formations= new Formations();            
  26.             $form $this->createForm(FormationType::class, $formations);   
  27.             $form->handleRequest($request); 
  28.     
  29.             if ($form->isSubmitted() && $form->isValid()){
  30.                 $this->manager->persist($formations); 
  31.                 $this->manager->flush();  
  32.                 return $this->redirectToRoute('app_formations_all');
  33.     
  34.             }
  35.     
  36.             return $this->render('formations/ajoutformation.html.twig', [
  37.                 'formFormation' => $form->createView(),  
  38.                 
  39.             ]); 
  40.         } 
  41.     /**
  42.      * @Route("/admin/all/formations", name="admin_app_formation_all") 
  43.      */
  44.     public function allformationsAdmin(): Response 
  45.     {
  46.         
  47.         $allTable $this->manager->getRepository(Formations::class)->findAll();   
  48.         // dd($formations);
  49.         return $this->render('formations/gestionformations.html.twig', [ 
  50.             'formations' => $allTable,  
  51.         ]);   
  52.     
  53.     } 
  54.     
  55.     /**
  56.      * @Route("/formations", name="app_formations")
  57.      */
  58.     public function index(): Response
  59.     {
  60.         return $this->render('formations/index.html.twig', [
  61.             'controller_name' => 'FormationsController',
  62.         ]);
  63.     }
  64.     // *************************AFFICHAGE DE TOUTES LES FORMATIONS 
  65.     /**
  66.      * @Route("/all/formations", name="app_formations_all") 
  67.      */
  68.     public function allformation(): Response 
  69.     {
  70.         $formations $this->manager->getRepository(Formations::class)->findAll();  
  71.         // dd($formations);
  72.         return $this->render('formations/allformations.html.twig', [ 
  73.             'formations' => $formations
  74.         ]);  
  75.     
  76.     } 
  77.     // **********************************************COTER ADMIN 
  78.     // *************************** AFFICHAGE MODIFICATION ET SUPPRESSION 
  79.     /**
  80.      * @Route("/admin/formations/delete/{id}", name="app_admin_formations_delete") 
  81.      */
  82.     public function formationsDelete(Formations $formations): Response 
  83.     {
  84.         $this->manager->remove($formations); 
  85.         $this->manager->flush(); 
  86.         return $this->redirectToRoute('app_formations_all');            
  87.         
  88.     }
  89.     /**
  90.      * @Route("/admin/formations/edit/{id}", name="app_admin_formations_edit")
  91.      */
  92.     public function formationsEdit(Formations $formationsRequest $request): Response 
  93.     {
  94.             $formEdit $this->createForm(FormationType::class, $formations);
  95.             $formEdit->handleRequest($request); 
  96.             if ($formEdit->isSubmitted() && $formEdit->isValid()) {
  97.                 $this->manager->persist($formations);  
  98.                 $this->manager->flush(); 
  99.                 return $this->redirectToRoute('app_formations_all');
  100.             }
  101.             return $this->render('formations/editformations.html.twig', [
  102.                 'formformations' => $formEdit->createview(), 
  103.             ]);    
  104.     }
  105.     
  106. }