iifast

ClubController.php

Mar 11th, 2020
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.24 KB | None | 0 0
  1. //ClubController.php
  2. <?php
  3.  
  4. namespace ClubBundle\Controller;
  5.  
  6. use ClubBundle\Entity\Club;
  7. use ClubBundle\Form\ClubType;
  8.  
  9. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  10. use Symfony\Component\HttpFoundation\Response;
  11.  
  12. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  13. use Symfony\Component\HttpFoundation\Request;
  14.  
  15.  
  16.  
  17. //change the name of this class from DefaultController to → class ClubController extends Controller
  18. class ClubController extends Controller
  19. {
  20.     public function indexAction()
  21.     {
  22.         return new Response("Bonjour");
  23.  
  24.         //definir new route qui veut m'amener a ce passsage → routing specifique :
  25.         // C:\wamp64\www\EspritClub\src\ClubBundle\Resources\config\routing.yml
  26.  
  27. /*
  28.         $classe="3A9";
  29.         return new Response("Bonjour".$classe);
  30.  
  31.         //(after homepage . png )  → passer une variable  Bonjour3A9
  32. */
  33. }
  34.    /* public function homeAction()
  35.     {
  36.         return $this->render('@Club/Club/homepage.html.twig');
  37.         //picture ( ScreenShot ) : homepage.png
  38.         //afficher depuis la vue ( thats why we use render ) + add the view path .
  39.         //then go to : C:\wamp64\www\EspritClub\src\ClubBundle\Resources\views\Club    and create new directory
  40.         // copy EspritClub\src\ClubBundle\Resources\views\Default\index.html.twig and
  41.         // paste in  → EspritClub\src\ClubBundle\Resources\views\Club
  42.         // we added new .html.twig to our \views\Club\homePage.html.twig
  43.     }
  44.     */
  45.  
  46.     public function homeAction()
  47.     {
  48.         return $this->render('@Club/Club/homepage.html.twig');}
  49.  
  50.         public function readAction($nom)
  51.     {
  52.         return $this->render('@Club/Club/read.html.twig',array('n'=>$nom));
  53.         // use twig pour separer partie traitement et partie presentation.
  54.     }
  55.     public function listAction()
  56.         //tableau (.../list  , et si je veux changer [chrome] /list → /tableau )
  57.         // je dois changer routing specifique + nom de la fonction → public function tableauAction
  58.     {
  59.         $formations = array();
  60.         $formations[0]= array('ref'=>'F1','titre'=>'Symfony 4');
  61.         $formations[1]= array('ref'=>'F2','titre'=>'PHP');
  62.         $formations[2]= array('ref'=>'F3','titre'=>'TWIGS');
  63.  
  64.         return $this->render("@Club/Club/details.html.twig",array('f'=>$formations));
  65.         // twig only knows f , et on parcourir f dans twig.
  66.  
  67.  
  68.     }
  69.  
  70.     public function showAction($titre){
  71.         return $this->render("@Club/Club/moredetails.html.twig",array('t'=>$titre));
  72.  
  73.     }
  74.  
  75.     //S3 - Affichage de BD :
  76.                          /***** affichage club ****/
  77.     public function read1Action()
  78.     {
  79.         $clubs = $this-> getDoctrine()
  80.             ->getRepository(Club::class)->findAll();
  81.         return $this->render('@Club/Club/read1.html.twig' , array('clubs' => $clubs )) ;
  82.  
  83.     }
  84.  
  85.                          /***** supprimer club ****/
  86.     public function deleteAction($id){
  87.        $em = $this->getDoctrine()->getManager();
  88.         $club= $em->getRepository(Club::class)->find($id);
  89.         $em->remove($club);
  90.         $em->flush();
  91.         return $this->redirectToRoute("club_read1");   //← nom de la route pour l'afficher !
  92. }
  93.  
  94.  
  95.                         /***** ajouterdb club ****/
  96.     public function  ajouterdbAction (Request $request)
  97.         {   $modele=new club();
  98.             $em=$this->getDoctrine()->getManager();
  99.             $form=$this->createForm(ClubType::class,$modele);
  100.  
  101.             $form->handleRequest($request);
  102.             if($form->isSubmitted() and $form->isValid())
  103.             {
  104.                 $em->persist($modele);
  105.                 $em->flush();
  106.                 return$this->redirectToRoute('club_read1');
  107.             }
  108.             return $this->render('@Club/Club/ajouterdb.html.twig',array('form'=>$form->createView()));
  109.  
  110.     }
  111.  
  112.                         /***** update club ****/
  113.     public function  updateAction ( Request $request ,int $id)
  114.     {
  115.         $em=$this->getDoctrine()->getManager();
  116.         $Club=$em->getRepository(Club::class)->find($id);
  117.         $form=$this->createForm(ClubType::class,$Club);
  118.         $form->handleRequest($request);
  119.  
  120.         if($form->isSubmitted())
  121.         {
  122.             $em->flush();
  123.             return$this->redirectToRoute('club_read1');
  124.         }
  125.         return $this->render('@Club/Club/ajouterdb.html.twig',array('form'=>$form->createView()));
  126.     }
  127.  
  128.                             /***** update nom club ****/
  129.     public function  update1Action ( Request $request ,int $id)
  130.     {
  131.         $em=$this->getDoctrine()->getManager();
  132.         $Club=$em->getRepository(Club::class)->find($id);
  133.  
  134.         if($request->isMethod('post'))
  135.         {
  136.             $Club->setNom($request->get('nom'));
  137.             $em=$this->getDoctrine()->getManager();
  138.             $em->flush();
  139.             return$this->redirectToRoute('club_read1');
  140.         }
  141.         return $this->render('@Club/Club/updatedb.html.twig',array('form'=>$Club));
  142.  
  143.     }
  144.  
  145.  
  146.     public function trouverDomaineAction(){
  147.         $repository = $this->getDoctrine()->getManager()->getRepository(club::class);
  148.         $listclubs = $repository->myfindDomaine();
  149.         return ($this->render('@Club/Club/listeDQL.html.twig',array("listeclubs"=>$listclubs)));
  150.  
  151.     }
  152.  
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment