src/DEVWEB/ColocationBundle/Controller/AdvertController.php
// controller de la vue postuler.html.twig
controller de la vue postuler.html.twig
controller de la vue postuler . html . twig
public function postulerAction(Request $request, $id)
  {
    $em = $this->getDoctrine()->getManager();
    $advert = $em->getRepository('DEVWEBColocationBundle:Advert')->find($id);
    $usr = $this->getUser();
    $nbPlace = $advert->getNbPlaces()-1;
    $advert->setNbPlaces($nbPlace);
    $advert->addUser($usr);
    $form = $this->get('form.factory')->create();
    if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
      $em = $this->getDoctrine()->getManager();
      $em->persist($advert);
      $em->flush();
      $request->getSession()->getFlashBag()->add('notice', 'Vous avez postulé à cette annonce.');
      return $this->redirectToRoute('devweb_colocation_home');
    }
    return $this->render('@DEVWEBColocation/Advert/postuler.html.twig', array(
      'advert' => $advert,
      'form'   => $form->createView()
    ));
  }
public function postulerAction ( Request $ request , $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ advert = $ em -> getRepository ( 'DEVWEBColocationBundle:Advert' ) -> find ( $ id ) ; $ usr = $ this -> getUser ( ) ; $ nbPlace = $ advert -> getNbPlaces ( ) - 1 ; $ advert -> setNbPlaces ( $ nbPlace ) ; $ advert -> addUser ( $ usr ) ; $ form = $ this -> get ( 'form.factory' ) -> create ( ) ; if ( $ request -> isMethod ( 'POST' ) && $ form -> handleRequest ( $ request ) -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ advert ) ; $ em -> flush ( ) ; $ request -> getSession ( ) -> getFlashBag ( ) -> add ( 'notice' , 'Vous avez postulé à cette annonce.'); return $ this -> redirectToRoute ( 'devweb_colocation_home' ) ; } return $ this -> render ( '@DEVWEBColocation/Advert/postuler.html.twig' , array ( 'advert' => $ advert , 'form' => $ form -> createView ( ) ) ) ; }
controller de la vue postuler.html.twig
controller de la vue postuler . html . twig