Example #1
0
 /**
  * Displays a form to edit an existing Post entity.
  *
  * @Route("/{id}/edit", requirements={"id" = "\d+"}, name="admin_category_edit")
  * @Method({"GET", "POST"})
  */
 public function editAction(Category $category, Request $request)
 {
     if (null === $this->getUser() || !$category->isAuthor($this->getUser())) {
         throw $this->createAccessDeniedException('Posts can only be edited by their authors.');
     }
     $entityManager = $this->getDoctrine()->getManager();
     $editForm = $this->createForm('AppBundle\\Form\\CategoryType', $category);
     $deleteForm = $this->createDeleteForm($category);
     $editForm->handleRequest($request);
     if ($editForm->isSubmitted() && $editForm->isValid()) {
         $category->setSlug($this->get('slugger')->slugify($post->getTitle()));
         $entityManager->flush();
         $this->addFlash('success', 'category.updated_successfully');
         return $this->redirectToRoute('admin_category_edit', array('id' => $category->getId()));
     }
     return $this->render('admin/category/edit.html.twig', array('post' => $category, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView()));
 }