public function insert($request)
 {
     $post = $this->_em->getRepository('BlogBundle:Post')->findOneById($request->get('post_id'));
     $parent_comment = $this->_em->getRepository('BlogBundle:Comment')->findOneById($request->get('comment_id'));
     $comment = new Comment();
     $comment->setText($request->get('comment')['text']);
     $comment->setPost($post);
     if ($parent_comment) {
         $comment->setComment($parent_comment);
     }
     $this->save($comment);
 }
 public function createCommentAction(Request $request)
 {
     $db = $this->getDoctrine()->getManager();
     $post = $db->getRepository('BlogBundle:Post')->findOneById($request->get('post_id'));
     if (!$post) {
         return $this->redirect($this->generateUrl('comment', array('post_id' => $post->getId())));
     }
     $comment = new Comment();
     $comment->setText($request->get('text'));
     $comment->setPost($post);
     // if comment relate to another comment
     if ($request->get('comment_id')) {
         $sub_comment = $db->getRepository('BlogBundle:Comment')->findOneById($request->get('comment_id'));
         $comment->setComment($sub_comment);
     }
     $db->getRepository('BlogBundle:Comment')->save($comment);
     return $this->redirect($this->generateUrl('comment', array('post_id' => $post->getId())));
 }