コード例 #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
 public function __construct(Comment $comment)
 {
     $this->id = $comment->getId();
     $this->setContent($comment->getContent());
     $this->setUserName($comment->getUserName());
     $this->setUserEmail($comment->getUserEmail());
     $this->setUserWeb($comment->getUserWeb());
 }
コード例 #3
0
 public function __construct(Comment $entity)
 {
     $this->content = (string) $entity->getContent();
     $this->userName = (string) $entity->getUserName();
     $this->userEmail = (string) $entity->getUserEmail();
     $this->userWeb = (string) $entity->getUserWeb();
     $this->status = (int) $entity->getStatus();
 }
コード例 #4
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;
 }