Example #1
0
 /**
  * @Route("/category/create")
  */
 public function createActionCategory()
 {
     $category = new Category();
     $category->setCategoryName('A Foo Bar');
     $em = $this->getDoctrine()->getManager();
     $em->persist($category);
     $em->flush();
     $categoryArray[] = $category->getId();
     $categoryArray[] = $category->getcategoryName();
     return new Response(json_encode($categoryArray));
 }
 /**
  * @Route("admin/edit/post/{slug}", name="edit_post")
  * @Template("@App/admin/editPost.html.twig")
  */
 public function editPostAction(Request $request, $slug)
 {
     $em = $this->getDoctrine()->getManager();
     $post = $em->getRepository('AppBundle:Post')->findOneBy(array('slug' => $slug));
     if (!$post) {
         return $this->redirectToRoute('page404');
     }
     $oldImage = $post->getPathImage();
     $form = $this->createForm(PostType::class, $post);
     $form_delete_image = [];
     $form_delete_image[$post->getSlug()] = $this->createFormDeleteImage($post->getSlug())->createView();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $newTags = $post->getNewTags();
         if (null !== $newTags) {
             $newTags = explode(',', trim($newTags));
             foreach ($newTags as $item) {
                 $tag = new Tag();
                 $tag->setTagName(trim($item));
                 $em->persist($tag);
                 $post->addTag($tag);
             }
         }
         $newCategory = $post->getNewCategory();
         if (null !== $newCategory) {
             $category = new Category();
             $category->setCategoryName(trim($newCategory));
             $em->persist($category);
             $post->setCategory($category);
         }
         $post->uploadImage();
         $post->setNewTags(null);
         $post->setNewCategory(null);
         $em->flush();
         $this->updateTagsCloud();
         return $this->redirectToRoute('admin_show');
     }
     return ['form' => $form->createView(), 'oldImage' => $oldImage, 'formDeleteImage' => $form_delete_image, 'slug' => $post->getSlug()];
 }