iifast

ClubController.php

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