public function load(ObjectManager $manager) { $faker = Factory::create(); for ($i = 0; $i < 50; $i++) { static $id = 1; $post = new Post(); $post->setTitle($faker->sentence); $post->setAuthorEmail('*****@*****.**'); $post->setImageName("images/post/foto{$id}.jpg"); $post->setContent($faker->realText($maxNbChars = 5000, $indexSize = 2)); $marks = array(); for ($q = 0; $q < rand(1, 10); $q++) { $marks[] = rand(1, 5); } $post->setMarks($marks); $post->addMark(5); $manager->persist($post); $this->addReference("{$id}", $post); $id = $id + 1; $rand = rand(3, 7); for ($j = 0; $j < $rand; $j++) { $comment = new Comment(); $comment->setAuthorEmail('*****@*****.**'); $comment->setCreatedBy('user_user'); $comment->setContent($faker->realText($maxNbChars = 500, $indexSize = 2)); $comment->setPost($post); $post->getComments()->add($comment); $manager->persist($comment); $manager->flush(); } } $manager->flush(); }
/** * @Route("/mark/{postSlug}/new", name = "mark_new") * @Method("POST") * @ParamConverter("post", options={"mapping": {"postSlug": "slug"}}) */ public function markNewAction(Post $post, Request $request) { $form = $this->createForm(MarkType::class); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $mark = $form->getData(); $entityManager = $this->getDoctrine()->getManager(); $post->addMark($mark['mark']); $entityManager->flush(); return $this->redirectToRoute('blog_post', array('slug' => $post->getSlug())); } return $this->render('blog/_mark_form.html.twig', array('post' => $post, 'form' => $form->createView())); }