Exemple #1
0
 public function createAction($blog_id)
 {
     $user = $this->get('security.context')->getToken()->getUser();
     $blog = $this->getBlog($blog_id);
     $comment = new Comment();
     $comment->setBlog($blog);
     $comment->setUser($user);
     $request = $this->getRequest();
     $form = $this->createForm(new CommentType(), $comment);
     $form->bindRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getEntityManager();
         $em->persist($comment);
         $em->flush();
         $this->get('session')->setFlash('blogger-notice', 'Successfully created!');
         return $this->redirect($this->generateUrl('VenuBlogBundle_blog_show', array('id' => $comment->getBlog()->getId(), 'slug' => $comment->getBlog()->getSlug())) . '#comment-' . $comment->getId());
     }
     return $this->render('VenuBlogBundle:Comment:create.html.twig', array('comment' => $comment, 'form' => $form->createView()));
 }
Exemple #2
0
 public function load(\Doctrine\Common\Persistence\ObjectManager $manager)
 {
     $comment = new Comment();
     $comment->setUser($manager->merge($this->getReference('user')));
     $comment->setComment('I love symfony');
     $comment->setBlog($manager->merge($this->getReference('blog-1')));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser($manager->merge($this->getReference('user')));
     $comment->setComment('I love symfony2');
     $comment->setBlog($manager->merge($this->getReference('blog-1')));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser($manager->merge($this->getReference('user')));
     $comment->setComment('This is great');
     $comment->setBlog($manager->merge($this->getReference('blog-2')));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser($manager->merge($this->getReference('user')));
     $comment->setComment('This is great2 ');
     $comment->setBlog($manager->merge($this->getReference('blog-2')));
     $comment->setCreatedAt(new \DateTime("2011-07-23 06:15:20"));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser($manager->merge($this->getReference('user')));
     $comment->setComment('This is great3');
     $comment->setBlog($manager->merge($this->getReference('blog-2')));
     $comment->setCreatedAt(new \DateTime("2011-07-23 06:18:35"));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser($manager->merge($this->getReference('user')));
     $comment->setComment('This is great3');
     $comment->setBlog($manager->merge($this->getReference('blog-2')));
     $comment->setCreatedAt(new \DateTime("2011-07-23 06:22:53"));
     $manager->persist($comment);
     $manager->flush();
 }