public function newRootAction(Request $request) { $em = $this->get('doctrine.orm.entity_manager'); $data = $request->request->get('category'); $nature = $this->getDoctrine()->getRepository('ChewbaccaCoreBundle:Nature')->findOneById($data['nature']); if (!$nature) { throw $this->createNotFoundException('The nature does not exist'); } $category = new Category(); $category->setNature($em->getReference("ChewbaccaCoreBundle:Nature", $data['nature'])); $form = $this->createForm(new CategoryRootType(), $category); if ($request->getMethod() == 'POST') { $form->bindRequest($request); if ($form->isValid()) { #$category = $form->getData(); #$em->persist($category->getNature()); $em->persist($category); $em->flush(); return $this->redirect($this->generateUrl('categories_roots', array('nature_title' => $nature))); } } return $this->render('ChewbaccaBackendCoreBundle:Categories:roots.html.twig', array('roots' => array(), 'form' => $form->createView())); }
/** * Add categories * * @param Chewbacca\CoreBundle\Entity\Category $categories */ public function addCategory(\Chewbacca\CoreBundle\Entity\Category $categories) { $this->categories[$categories->getId()] = $categories; }