public function load(ObjectManager $manager) { $comment = new Comment(); $comment->setUser('Olik1'); $comment->setComment('tram param1'); $comment->setBlog($manager->merge($this->getReference('blog-1'))); $manager->persist($comment); $comment = new Comment(); $comment->setUser('Olik2'); $comment->setComment('tram param'); $comment->setBlog($manager->merge($this->getReference('blog-1'))); $manager->persist($comment); $comment = new Comment(); $comment->setUser('Olik3'); $comment->setComment('tram param2'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $manager->persist($comment); $comment = new Comment(); $comment->setUser('Olik4'); $comment->setComment('tram param3'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $manager->persist($comment); $comment = new Comment(); $comment->setUser('Olik5'); $comment->setComment('tram param4'); $comment->setBlog($manager->merge($this->getReference('blog-1'))); $manager->persist($comment); $manager->flush(); }
public function createAction(Request $request, $blog_id) { $blog_id = (int)$blog_id; $blog = $this->getBlog($blog_id); $comment = new Comment(); $comment->setBlog($blog); // $comment->setCreated(date("Y-m-d H:i:s")); // $comment->setUpdated(date("Y-m-d H:i:s")); $form = $this->createForm(new CommentType(), $comment); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine() ->getEntityManager(); $em->persist($comment); $em->flush(); return $this->redirect($this->generateUrl('BloggerBlogBundle_blog_show', array( 'id' => $comment->getBlog()->getId(), 'slug' => $comment->getBlog()->getSlug())) . '#comment-' . $comment->getId() ); } return $this->render('BloggerBlogBundle:Comment:create.html.twig', ['comment' => $comment, 'form' => $form->createView()]); }
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()) { return $this->redirect($this->generateUrl('blogger_blog_blog_show', array('id' => $comment->getBlog()->getId())) . '#comment-' . $comment->getId()); } return $this->render('BloggerBlogBundle:Comment:create.html.twig', array('comment' => $comment, 'form' => $form->createView())); }
/** * @Route( * path="/comment/{blog_id}", * name="blogger_blog_comment_create", * requirements={"blog_id"="\d+"} * ) * @ParamConverter("blog", class="BloggerBlogBundle:Blog", options={"mapping": {"blog_id": "id"}}) * @Method({"POST"}) */ public function createAction(Blog $blog) { $comment = new Comment(); $comment->setBlog($blog); $request = $this->container->get('request'); $form = $this->createForm(new CommentType(), $comment); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $em->persist($comment); $em->flush(); return $this->redirect($this->generateUrl('blogger_blog_show', ['id' => $comment->getBlog()->getId(), 'slug' => $comment->getBlog()->getSlug() . '#comment' . $comment->getId()]) . '#comment-' . $comment->getId()); } return $this->render('BloggerBlogBundle:Comment:create.html.twig', ['comment' => $comment, 'form' => $form->createView()]); }
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->submit($request); if ($form->isValid()) { if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($comment); $em->flush(); return $this->redirect($this->generateUrl('BloggerBlogBundle_blog_show', array('id' => $comment->getBlog()->getId(), 'slug' => $comment->getBlog()->getSlug())) . '#comment-' . $comment->getId()); } } return $this->render('BloggerBlogBundle:Comment:create.html.twig', array('comment' => $comment, 'form' => $form->createView())); }
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()) { // TODO: Persist the comment entity $em = $this->getDoctrine()->getManager(); //gets entityManager $em->persist($comment); //saves the comment to the DB $em->flush(); //writes in DB return $this->redirect($this->generateUrl('BloggerBlogBundle_blog_show', array('id' => $comment->getBlog()->getId())) . '#comment-' . $comment->getId()); } return $this->render('BloggerBlogBundle:Comment:create.html.twig', array('comment' => $comment, 'form' => $form->createView())); }
public function testSubmitValidData() { $client = WebTestCase::createClient(); $container = $client->getContainer(); $formData = ['user' => 'test user', 'comment' => 'wish']; $comment = new Comment(); $comment->setUser($formData['user']); $comment->setComment($formData['comment']); $form = $container->get('form.factory')->create(new CommentType(), $comment); $form->submit($formData); $this->assertTrue($form->isSynchronized()); $this->assertEquals($comment, $form->getData()); $this->assertFalse($form->isValid()); $formErrors = $form->getErrors(true); $this->assertEquals('Similar comment is already exists.', $formErrors->getChildren()->getMessage()); $this->assertEquals(1, $formErrors->count()); $view = $form->createView(); $children = $view->children; foreach ($formData as $key => $value) { $this->assertArrayHasKey($key, $children); } }
public function load(ObjectManager $manager) { $comment = new Comment(); $comment->setTestuser('symfony'); $comment->setComment('To make a long story short. You can\'t go wrong by choosing Symfony! And no one has ever been fired for using Symfony.'); $comment->setBlog($manager->merge($this->getReference('blog-1'))); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('David'); $comment->setComment('To make a long story short. Choosing a framework must not be taken lightly; it is a long-term commitment. Make sure that you make the right selection!'); $comment->setBlog($manager->merge($this->getReference('blog-1'))); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Dade'); $comment->setComment('Anything else, mom? You want me to mow the lawn? Oops! I forgot, New York, No grass.'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Kate'); $comment->setComment('Are you challenging me? '); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $comment->setCreated(new \DateTime("2011-07-23 06:15:20")); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Dade'); $comment->setComment('Name your stakes.'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $comment->setCreated(new \DateTime("2011-07-23 06:18:35")); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Kate'); $comment->setComment('If I win, you become my slave.'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $comment->setCreated(new \DateTime("2011-07-23 06:22:53")); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Dade'); $comment->setComment('Your SLAVE?'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $comment->setCreated(new \DateTime("2011-07-23 06:25:15")); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Kate'); $comment->setComment('You wish! You\'ll do shitwork, scan, crack copyrights...'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $comment->setCreated(new \DateTime("2011-07-23 06:46:08")); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Dade'); $comment->setComment('And if I win?'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $comment->setCreated(new \DateTime("2011-07-23 10:22:46")); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Kate'); $comment->setComment('Make it my first-born!'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $comment->setCreated(new \DateTime("2011-07-23 11:08:08")); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Dade'); $comment->setComment('Make it our first-date!'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $comment->setCreated(new \DateTime("2011-07-24 18:56:01")); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Kate'); $comment->setComment('I don\'t DO dates. But I don\'t lose either, so you\'re on!'); $comment->setBlog($manager->merge($this->getReference('blog-2'))); $comment->setCreated(new \DateTime("2011-07-25 22:28:42")); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Stanley'); $comment->setComment('It\'s not gonna end like this.'); $comment->setBlog($manager->merge($this->getReference('blog-3'))); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Gabriel'); $comment->setComment('Oh, come on, Stan. Not everything ends the way you think it should. Besides, audiences love happy endings.'); $comment->setBlog($manager->merge($this->getReference('blog-3'))); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Mile'); $comment->setComment('Doesn\'t Bill Gates have something like that?'); $comment->setBlog($manager->merge($this->getReference('blog-5'))); $manager->persist($comment); $comment = new Comment(); $comment->setTestuser('Gary'); $comment->setComment('Bill Who?'); $comment->setBlog($manager->merge($this->getReference('blog-5'))); $manager->persist($comment); $manager->flush(); }
public function getBlog() { $this->__load(); return parent::getBlog(); }