public function addAction($categoryId, Request $request) { $article = new Article(); $em = $this->getDoctrine()->getManager(); if ($categoryId == null) { $category = $em->getRepository('LCVPlatformBundle:Category')->findOneByName('Default'); } else { $category = $em->getRepository('LCVPlatformBundle:Category')->findOneById($categoryId); } $article->setCategory($category); $form = $this->createForm(new ArticleType(), $article); if ($form->handleRequest($request)->isValid()) { $article->setAuthor($this->getUser()); $article->setRate(new Rating()); $em->persist($article); $em->flush(); $request->getSession()->getFlashBag()->add('success', 'Article bien enregistré.'); return $this->redirect($this->generateUrl('lcv_platform_view', array('id' => $article->getId()))); } return $this->render('LCVPlatformBundle:Article:add.html.twig', array('article' => $article, 'form' => $form->createView())); }
/** * Add articles * * @param \LCV\PlatformBundle\Entity\Article $articles * @return Category */ public function addArticle(\LCV\PlatformBundle\Entity\Article $article) { $this->articles[] = $article; $article->setCategory($this); return $this; }