public function load(ObjectManager $manager) { $faker = Factory::create(); $comment = new Comment(); $comment->setPost($this->getReference('post'))->setText($faker->text(15)); $manager->persist($comment); $manager->flush(); }
/** * @Route("/{slug}", name="_BlogView") * @Template() * @Method("GET") */ public function viewAction($slug) { $em = $this->getDoctrine()->getEntityManager(); $post = $em->getRepository('workshopBlogBundle:Post')->findOneBySlug($slug); if (!$post) { throw new NotFoundHttpException('The specified entity does not exist.'); } $comment = new Comment(); $comment->setPost($post); $form = $this->createForm(new ViewCommentType(), $comment); return array('post' => $post, 'comments' => $post->getComments(), 'form' => $form->createView()); }