public function createAction(Request $request, $blog_id) { $blog = $this->getBlog($blog_id); $comment = new Comment(); $comment->setBlog($blog); $form = $this->createForm(CommentType::class, $comment); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($comment); $em->flush(); return $this->redirect($this->generateUrl('blog_show', array('id' => $comment->getBlog()->getId())) . '#comment-' . $comment->getId()); } return $this->render(':Comment:create.html.twig', array('comment' => $comment, 'form' => $form->createView())); }
public function load(ObjectManager $manager) { for ($i = 1; $i < 151; $i++) { $comment = new Comment(); $comment->setUser('Hans Meier'); $comment->setComment('Huh so funny'); if ($i % 2 == 0) { $blog = 'blog-1'; } else { $blog = 'blog-2'; } $comment->setBlog($this->getReference($blog)); $manager->persist($comment); } $manager->flush(); }