RestBundle\Controller\RestController::newCommentAction PHP Method

newCommentAction() public method

Creates a new comment from the submitted data.
public newCommentAction ( Request $request, integer $id ) : FOS\RestBundle\View\View
$request Symfony\Component\HttpFoundation\Request
$id integer
return FOS\RestBundle\View\View
    public function newCommentAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();
        $post = $em->getRepository('AppBundle:Post')->find($id);
        $comment = new Comment();
        $comment->setPost($post);
        $form = $this->createForm(new CommentRestType(), $comment);
        $form->submit($request);
        if ($form->isValid()) {
            $em->persist($comment);
            $em->flush();
            return $this->routeRedirectView('api_v1_get_comment', array('id' => $comment->getId()));
        }
        $view = $this->view($form)->setTemplate('RestBundle:Comment:newComment.html.twig');
        return $this->handleView($view);
    }