BlogBundle/Controller/PostController.php
public function newAction(Request $request)
    {
        $post = new Post();
        $form = $this->createForm('BlogBundle\Form\PostType', $post, array('translator' => $this->get('translator') ));
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $user = $this->container->get('security.token_storage')->getToken()->getUser();
            $post->setActor($user);
            $em = $this->getDoctrine()->getManager();
            $em->persist($post);
            $em->flush();

            $this->get('session')->getFlashBag()->add('success', 'post.created');
            
            return $this->redirectToRoute('blog_post_index');
        }

        return array(
            'category' => $post,
            'form' => $form->createView(),
        );
    }
public function newAction(Request $request)
    {
        $post = new Post();
        $form = $this->createForm('BlogBundle\Form\PostType', $post, array('translator' => $this->get('translator') ));
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $user = $this->container->get('security.token_storage')->getToken()->getUser();
            $post->setActor($user);
            $em = $this->getDoctrine()->getManager();
            $em->persist($post);
            $em->flush();

            $this->get('session')->getFlashBag()->add('success', 'post.created');
            
            return $this->redirectToRoute('blog_post_index');
        }

        return array(
            'category' => $post,
            'form' => $form->createView(),
        );
    }
Creates a new Post entity.

@Route("/new")
@Method({"GET", "POST"})
@Template()