public function createAction($blog_id) { $blog = $this->getBlog($blog_id); $comment = new Comment(); $comment->setBlog($blog); $request = $this->getRequest(); $form = $this->createForm(new CommentType(), $comment); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($comment); $em->flush(); $this->get('session')->getFlashBag()->add('notice', 'Your message has been sent!'); return $this->redirect($this->generateUrl('FilBlogBundle_blog_show', array('id' => $comment->getBlog()->getId(), 'slug' => $comment->getBlog()->getSlug())) . '#comment-' . $comment->getId()); } return $this->render('FilBlogBundle:Blog:view.html.twig', array('comment' => $comment, 'form' => $form->createView())); }
/** * * @ParamConverter("blog", options={"mapping": {"blog_id": "id"}}) */ public function viewAction(Blog $blog) { $em = $this->getDoctrine()->getManager(); $comment = new Comment(); $comment->setBlog($blog); $request = $this->getRequest(); $form = $this->createForm(new CommentType(), $comment); //$form->bind($request); //$blog = $em->getRepository('FilBlogBundle:Blog')->find($id); //if (null === $blog) { // throw new NotFoundHttpException("L'annonce ayant l'id ".$id. "n'existe pas."); // } $blog->setView($blog->getView() + 1); $em->persist($blog); $em->flush(); $listComments = $em->getRepository('FilBlogBundle:Comment')->findBy(array('blog' => $blog)); $tags = $em->getRepository('FilBlogBundle:Blog')->getTags(); $tagWeights = $em->getRepository('FilBlogBundle:Blog')->getTagWeights($tags); return $this->render('FilBlogBundle:Blog:view.html.twig', array('blog_id' => $blog->getId(), 'blog' => $blog, 'listComments' => $listComments, 'comment' => $comment, 'form' => $form->createView(), 'tags' => $tagWeights)); }
/** * Add comment * * @param \Fil\BlogBundle\Entity\Comment $comment * @return Blog */ public function addComment(\Fil\BlogBundle\Entity\Comment $comment) { $this->comments[] = $comment; $comment->setBlog($this); return $this; }