Guest User

Untitled

a guest
Oct 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. /**
  2. * @Route("/agency/post", name="agency_post")
  3. */
  4. public function agencyNewAd(Request $request)
  5. {
  6. // $agency = $this->get('security.token_storage')->getToken()->getUser(); ( this didn't worked .. )
  7. $form = $this->createForm(AgencyNewAdType::class, array(
  8. 'postedBy' => $this->getUser(),
  9. ));
  10. $form->handleRequest($request);
  11.  
  12. if ($form->isSubmitted() && $form->isValid()) {
  13.  
  14. $ad = $form->getData();
  15.  
  16. // save the task to the database
  17. $em = $this->getDoctrine()->getManager();
  18. $em->persist($ad);
  19. $em->flush();
  20. // return new Response('Saved new Post with id ' . $ad->getId());
  21. return $this->redirectToRoute('agency_admin');
  22. }
  23. return $this->render('agency/new_ad.html.twig', [
  24. 'adForm' => $form->createView()
  25. ]);
  26. }
Add Comment
Please, Sign In to add comment