Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Controller;
- use AppBundle\Entity\Post;
- use AppBundle\Form\PostType;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\Request;
- /**
- * Class AdminController
- * @package AppBundle\Controller
- * @Route("/admin")
- */
- class AdminController extends Controller
- {
- /**
- * @return \Symfony\Component\HttpFoundation\Response
- * @Security("has_role('ROLE_ADMIN')")
- * @Route("/post/new")
- */
- public function newPostAction(Request $request)
- {
- $post = new Post();
- $form = $this->createForm(PostType::class, $post);
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- $em = $this->getDoctrine()->getManager();
- $em->persist($post);
- $em->flush();
- }
- return $this->render('admin/post/new.html.twig', [
- 'form' => $form->createView()
- ]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment