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->bindRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $em->persist($comment); $em->flush(); return $this->redirect($this->generateUrl('HamdiBlogBundle_blog_show', array('id' => $comment->getBlog()->getId())) . '#comment-' . $comment->getId()); } return $this->render('HamdiBlogBundle:Comment:create.html.twig', array('comment' => $comment, 'form' => $form->createView())); }
public function listcommentAction(Request $request) { if ('POST' === $request->getMethod()) { $nom = $request->request->get('auteur'); $msg = $request->request->get('message'); $id = $request->request->get('idblog'); $em = $this->getDoctrine()->getEntityManager(); $blog = $em->getRepository('HamdiBlogBundle:Blog')->find($id); $comment = new Comment(); $comment->setUser($nom); $comment->setComment($msg); $comment->setBlog($blog); $em->persist($comment); $em->flush(); } return $this->redirect($this->generateUrl('HamdiBlogBundle_blog_show', array('id' => $id))); }