src/PHPDish/Bundle/PostBundle/Controller/CommentController.php
public function addAction($id, Request $request)
    {
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
        $post = $this->getPostManager()->findPostById($id);
        $comment = $this->getPostCommentManager()->createComment($post, $this->getUser());
        $form = $this->createForm(CommentType::class, $comment);
        $form->handleRequest($request);
        $view = $this->view();
        if ($form->isSubmitted() && $form->isValid()) {
            $this->getPostCommentManager()->saveComment($comment);

            //触发文章评论事件
            $this->get('event_dispatcher')->dispatch(Events::POST_COMMENTED, new PostCommentedEvent($post, $comment));

            $view->setData(['comment' => $comment])
                ->setStatusCode(static::HTTP_CREATED)
                ->setContext((new Context())->setGroups(['Default']));
        } else {
            $view->setData([ 'form' => $form])
                ->setStatusCode(static::HTTP_BAD_REQUEST);
        }

        return $this->handleView($view);
    }
public function addAction($id, Request $request)
    {
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
        $post = $this->getPostManager()->findPostById($id);
        $comment = $this->getPostCommentManager()->createComment($post, $this->getUser());
        $form = $this->createForm(CommentType::class, $comment);
        $form->handleRequest($request);
        $view = $this->view();
        if ($form->isSubmitted() && $form->isValid()) {
            $this->getPostCommentManager()->saveComment($comment);

            //触发文章评论事件
            $this->get('event_dispatcher')->dispatch(Events::POST_COMMENTED, new PostCommentedEvent($post, $comment));

            $view->setData(['comment' => $comment])
                ->setStatusCode(static::HTTP_CREATED)
                ->setContext((new Context())->setGroups(['Default']));
        } else {
            $view->setData([ 'form' => $form])
                ->setStatusCode(static::HTTP_BAD_REQUEST);
        }

        return $this->handleView($view);
    }
添加评论.

@Route("/posts/{id}/comments", name="comment_add")
@Method("POST")

@param int     $id
@param Request $request

@return Response