src/DEVWEB/ColocationBundle/Controller/AdvertController.php
// controller de la vue search.html.twig
controller de la vue search.html.twig
controller de la vue search . html . twig
public function searchAction(Request $request)
  {
    $listAdverts = null;
    $form = $this->createFormBuilder(null)
    ->add('search',          TextType::class)
    ->add('parametre',            ChoiceType::class, array('choices'  => array('Titre' => 1,
                                                                          'Type' => 2,
                                                                          'Auteur' => 3
                                                                          )))
    ->add('Rechercher',      SubmitType::class)
    ->getForm();
    $repository = $this
      ->getDoctrine()
      ->getManager()
      ->getRepository('DEVWEBColocationBundle:Advert')
    ;
    if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
      $donnees = $form->getData();
      if($donnees['parametre'] == '1'){
        $listAdverts = $repository->findBy(array('title' => $donnees['search']));
        foreach ($listAdverts as $advert) {
        }
      }
      else if($donnees['parametre'] == '2'){
        $listAdverts = $repository->findBy(array('type' => $donnees['search']));
        foreach ($listAdverts as $advert) {
        }
      }
      else if($donnees['parametre'] == '3'){
        $listAdverts = $repository->findBy(array('author' => $donnees['search']));
        foreach ($listAdverts as $advert) {
        }
      }
    }
    return $this->render('@DEVWEBColocation/Advert/search.html.twig', array(
      'listAdverts' => $listAdverts,
      'form' => $form->createView()
    ));
  }
public function searchAction ( Request $ request ) { $ listAdverts = null ; $ form = $ this -> createFormBuilder ( null ) -> add ( 'search' , TextType :: class ) -> add ( 'parametre' , ChoiceType :: class , array ( 'choices' => array ( 'Titre' => 1 , 'Type' => 2 , 'Auteur' => 3 ) ) ) -> add ( 'Rechercher' , SubmitType :: class ) -> getForm ( ) ; $ repository = $ this -> getDoctrine ( ) -> getManager ( ) -> getRepository ( 'DEVWEBColocationBundle:Advert' ) ; if ( $ request -> isMethod ( 'POST' ) && $ form -> handleRequest ( $ request ) -> isValid ( ) ) { $ donnees = $ form -> getData ( ) ; if ( $ donnees [ 'parametre' ] == '1' ) { $ listAdverts = $ repository -> findBy ( array ( 'title' => $ donnees [ 'search' ] ) ) ; foreach ( $ listAdverts as $ advert ) { } } else if ( $ donnees [ 'parametre' ] == '2' ) { $ listAdverts = $ repository -> findBy ( array ( 'type' => $ donnees [ 'search' ] ) ) ; foreach ( $ listAdverts as $ advert ) { } } else if ( $ donnees [ 'parametre' ] == '3' ) { $ listAdverts = $ repository -> findBy ( array ( 'author' => $ donnees [ 'search' ] ) ) ; foreach ( $ listAdverts as $ advert ) { } } } return $ this -> render ( '@DEVWEBColocation/Advert/search.html.twig' , array ( 'listAdverts' => $ listAdverts , 'form' => $ form -> createView ( ) ) ) ; }
controller de la vue search.html.twig
controller de la vue search . html . twig