/** * @param Request $request * @param $slug * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function addCommentAction(Request $request, $slug) { $comment = new Comment(); $post = $this->getEntity($slug, PostVoter::COMMENT, ['method' => "findBySlug"]); $comment->setPost($post); $form = $this->generateCommentForm($comment, $request); return $this->processCommentForm($form, $comment, $request); }
/** * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { $em = $this->getContainer()->get('doctrine')->getManager(); $parser = $this->getContainer()->get('lke_core.parse_csv'); $rows = $parser->parse(self::FILE); foreach ($rows as $row) { $comment = new Comment(); $comment->setUsername($row[self::USERNAME]); $comment->setContent($row[self::CONTENT]); $comment->setPost($this->getPost($row[self::POST_ID])); $em->persist($comment); } $em->flush(); $output->writeln("Comments loaded"); }