Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace ClubBundle\Controller;
- use ClubBundle\Entity\Club;
- use ClubBundle\Form\ClubType;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\Form\Extension\Core\Type\SubmitType;
- use Symfony\Component\HttpFoundation\Request;
- //change the name of this class from DefaultController to → class ClubController extends Controller
- class ClubController extends Controller
- {
- public function indexAction()
- {
- return new Response("Bonjour");
- //definir new route qui veut m'amener a ce passsage → routing specifique :
- // C:\wamp64\www\EspritClub\src\ClubBundle\Resources\config\routing.yml
- /*
- $classe="3A9";
- return new Response("Bonjour".$classe);
- //(after homepage . png ) → passer une variable Bonjour3A9
- */
- }
- /* public function homeAction()
- {
- return $this->render('@Club/Club/homepage.html.twig');
- //picture ( ScreenShot ) : homepage.png
- //afficher depuis la vue ( thats why we use render ) + add the view path .
- //then go to : C:\wamp64\www\EspritClub\src\ClubBundle\Resources\views\Club and create new directory
- // copy EspritClub\src\ClubBundle\Resources\views\Default\index.html.twig and
- // paste in → EspritClub\src\ClubBundle\Resources\views\Club
- // we added new .html.twig to our \views\Club\homePage.html.twig
- }
- */
- public function homeAction()
- {
- return $this->render('@Club/Club/homepage.html.twig');}
- public function readAction($nom)
- {
- return $this->render('@Club/Club/read.html.twig',array('n'=>$nom));
- // use twig pour separer partie traitement et partie presentation.
- }
- /***** List *****/
- public function listAction()
- //tableau (.../list , et si je veux changer [chrome] /list → /tableau )
- // je dois changer routing specifique + nom de la fonction → public function tableauAction
- {
- $formations = array();
- $formations[0]= array('ref'=>'F1','titre'=>'Symfony 4');
- $formations[1]= array('ref'=>'F2','titre'=>'PHP');
- $formations[2]= array('ref'=>'F3','titre'=>'TWIGS');
- return $this->render("@Club/Club/details.html.twig",array('f'=>$formations));
- // twig only knows f , et on parcourir f dans twig.
- }
- public function showAction($titre){
- return $this->render("@Club/Club/moredetails.html.twig",array('t'=>$titre));
- }
- //S3 - Affichage de BD :
- /***** affichage club ****/
- public function read1Action()
- {
- $clubs = $this-> getDoctrine()
- ->getRepository(Club::class)->findAll();
- return $this->render('@Club/Club/read1.html.twig' , array('clubs' => $clubs )) ;
- }
- /***** supprimer club ****/
- public function deleteAction($id){
- $em = $this->getDoctrine()->getManager();
- $club= $em->getRepository(Club::class)->find($id);
- $em->remove($club);
- $em->flush();
- return $this->redirectToRoute("club_read1"); //← nom de la route pour l'afficher !
- }
- @h@ /***** ajouterdb club ****/
- public function ajouterdbAction (Request $request)
- { $modele=new club();
- $em=$this->getDoctrine()->getManager();
- $form=$this->createForm(ClubType::class,$modele);
- $form->handleRequest($request);
- if($form->isSubmitted() and $form->isValid())
- {
- $em->persist($modele);
- $em->flush();
- return$this->redirectToRoute('club_read1');
- }
- return $this->render('@Club/Club/ajouterdb.html.twig',array('form'=>$form->createView()));
- }
- @h@ /***** update club ****/
- public function updateAction ( Request $request ,int $id)
- {
- $em=$this->getDoctrine()->getManager();
- $Club=$em->getRepository(Club::class)->find($id);
- $form=$this->createForm(ClubType::class,$Club);
- $form->handleRequest($request);
- if($form->isSubmitted())
- {
- $em->flush();
- return$this->redirectToRoute('club_read1');
- }
- return $this->render('@Club/Club/ajouterdb.html.twig',array('form'=>$form->createView()));
- }
- @h@ /***** update nom club ****/
- public function update1Action ( Request $request ,int $id)
- {
- $em=$this->getDoctrine()->getManager();
- $Club=$em->getRepository(Club::class)->find($id);
- if($request->isMethod('post'))
- {
- $Club->setNom($request->get('nom'));
- $em=$this->getDoctrine()->getManager();
- $em->flush();
- return$this->redirectToRoute('club_read1');
- }
- return $this->render('@Club/Club/updatedb.html.twig',array('form'=>$Club));
- }
- public function trouverDomaineAction(){
- $repository = $this->getDoctrine()->getManager()->getRepository(club::class);
- $listclubs = $repository->myfindDomaine();
- return ($this->render('@Club/Club/listeDQL.html.twig',array("listeclubs"=>$listclubs)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment