src/DEVWEB/ColocationBundle/Controller/AdvertController.php
// controller de la vue add.html.twig
controller de la vue add.html.twig
controller de la vue add . html . twig
public function addAction(Request $request)
  {
    $advert = new Advert();
    $form   = $this->get('form.factory')->create(AdvertType::class, $advert);
    if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
      $usr = $this->getUser();
      $usrname = $usr->getUsername();
      $advert->setAuthor($usrname);
      $em = $this->getDoctrine()->getManager();
      $em->persist($advert);
      $em->flush();
      $request->getSession()->getFlashBag()->add('notice', 'Annonce bien enregistrée.');
      return $this->redirectToRoute('devweb_colocation_view', array('id' => $advert->getId()));
    }
    return $this->render('@DEVWEBColocation/Advert/add.html.twig', array(
      'form' => $form->createView(),
    ));
  }
public function addAction ( Request $ request ) { $ advert = new Advert ( ) ; $ form = $ this -> get ( 'form.factory' ) -> create ( AdvertType :: class , $ advert ) ; if ( $ request -> isMethod ( 'POST' ) && $ form -> handleRequest ( $ request ) -> isValid ( ) ) { $ usr = $ this -> getUser ( ) ; $ usrname = $ usr -> getUsername ( ) ; $ advert -> setAuthor ( $ usrname ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ em -> persist ( $ advert ) ; $ em -> flush ( ) ; $ request -> getSession ( ) -> getFlashBag ( ) -> add ( 'notice' , 'Annonce bien enregistrée.') ; return $ this -> redirectToRoute ( 'devweb_colocation_view' , array ( 'id' => $ advert -> getId ( ) ) ) ; } return $ this -> render ( '@DEVWEBColocation/Advert/add.html.twig' , array ( 'form' => $ form -> createView ( ) , ) ) ; }
controller de la vue add.html.twig
controller de la vue add . html . twig