Guest User

Untitled

a guest
Nov 9th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use AppBundle\Entity\Post;
  6. use AppBundle\Form\PostType;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  9. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  10. use Symfony\Component\HttpFoundation\Request;
  11.  
  12. /**
  13.  * Class AdminController
  14.  * @package AppBundle\Controller
  15.  * @Route("/admin")
  16.  */
  17. class AdminController extends Controller
  18. {
  19.     /**
  20.      * @return \Symfony\Component\HttpFoundation\Response
  21.      * @Security("has_role('ROLE_ADMIN')")
  22.      * @Route("/post/new")
  23.      */
  24.     public function newPostAction(Request $request)
  25.     {
  26.         $post = new Post();
  27.         $form = $this->createForm(PostType::class, $post);
  28.  
  29.         $form->handleRequest($request);
  30.         if ($form->isSubmitted() && $form->isValid()) {
  31.             $em = $this->getDoctrine()->getManager();
  32.             $em->persist($post);
  33.             $em->flush();
  34.         }
  35.  
  36.         return $this->render('admin/post/new.html.twig', [
  37.             'form' => $form->createView()
  38.         ]);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment