Пример #1
0
 /**
  * Creates a new Comment entity.
  *
  * @Route("/{post_id}", name="_blog_comment_create", requirements={"post_id" = "\d+"}, defaults={"post_id" = "1" })
  * @Template()
  */
 public function indexAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $post = $em->getRepository('BlogBundle:Post')->find($request->get('post_id', false));
     if (!$post) {
         throw $this->createNotFoundException('Unable to find post.');
     }
     $comment = new Comment();
     $comment->setPost($post);
     $form = $this->createForm(new CommentType(), new CommentModel($comment));
     if ($request->getMethod() == 'POST') {
         $formHandler = new CommentHandler($form, $request, $comment, $em, $this->container->get('blog.sanitizer'));
         if ($formHandler->process()) {
             return $this->redirect($this->generateUrl('_comment_message'));
         }
     }
     return array('form' => $form->createView(), 'post' => $post);
 }
Пример #2
0
 /**
  *
  * @param  \Desarrolla2\Bundle\BlogBundle\Entity\Post $post
  * @return \Desarrolla2\Bundle\BlogBundle\Entity\Comment
  */
 protected function createCommentForPost(Post $post)
 {
     $comment = new Comment();
     $comment->setPost($post);
     return $comment;
 }