示例#1
0
 /**
  * @Route("/insert/category", name="insert_category")
  */
 public function insertCategoryAction(Request $request)
 {
     $category = new Category();
     $category->setAdded(new \DateTime('now'));
     $category->setAdminId($this->getUser()->getId());
     $form = $this->createForm(CategoryType::class, $category);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($category);
         $em->flush();
         return $this->redirectToRoute('insert_category');
     }
     $repository = $this->getDoctrine()->getRepository('AppBundle:Category');
     $categories = $repository->findByParent(NULL);
     return $this->render('category/insert.html.twig', array('form' => $form->createView(), 'categories' => $categories));
 }