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()) { // TODO: Persist the comment entity return $this->redirect($this->generateUrl('ThijsBlogBundle_blog_show', array('id' => $comment->getBlog()->getId())) . '#comment-' . $comment->getId()); } return $this->render('ThijsBlogBundle:Comment:create.html.twig', array('comment' => $comment, 'form' => $form->createView())); }
public function load(ObjectManager $manager) { $i = 1; $faker = \Faker\Factory::create(); while ($i <= 30) { $comment = new Comment(); $comment->setComment($faker->text($maxNbChars = 200)); $comment->setUser($faker->text($maxNbChars = 30)); $comment->setCreated($faker->dateTimeBetween('-1 years', '+1 month')); $rand = rand(1, 20); $comment->setPost($this->getReference('post-' . $rand)); $manager->persist($comment); ++$i; } $manager->flush(); }