Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /**
  5. * @Route("/admin/article/create" , name="admin.post.new")
  6. */
  7. public function new( Request $request){
  8.  
  9. $post = new Post() ;
  10. $post->setAutheur($this->getUser());
  11. $form = $this->createForm(PostType::class ,$post);
  12. $form->handleRequest($request);
  13.  
  14. if ($form->isSubmitted() && $form->isValid() ){
  15. $this->em->persist($post);
  16. $this-> em->flush();
  17. $this->addFlash('succes' , 'Bien! Créé avec succès');
  18. return $this->redirectToRoute('admin.post.index');
  19. }
  20. return $this->render('admin/posts/new.html.twig', [
  21. "post" => $post ,
  22. "form" => $form->createView()
  23. ]);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement