/** * @Route("/articles/new", name="articles_new") * @Method({"GET", "POST"}) */ public function newAction(Request $request) { $article = new Article(); $article->setPublishedAt(new \DateTime()); $form = $this->createForm(new ArticleType(), $article, ['action' => $this->generateUrl('articles_new'), 'method' => 'POST']); if ($request->getMethod() == 'POST') { $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($article); $em->flush(); $t = $this->get('translator'); $message = $t->trans('The %entity% has been saved.', ['%entity%' => $t->trans('Article')]); $this->addFlash('success', $message); return $this->redirect($this->generateUrl('articles')); } } return $this->render('@SymsiteBlog/Articles/new.html.twig', ['form' => $form->createView()]); }
public function load(ObjectManager $manager) { $statuses = Article::getStatuses(); for ($i = 1; $i < 100; $i++) { $article = new Article(); $article->setTitle(sprintf("Title: %03d", $i)); $article->setBody("Foo\nBar\n{$i}\n"); $article->setStatus($statuses[array_rand($statuses)]); $article->setPublishedAt(Carbon::today()); $manager->persist($article); } $manager->flush(); }