From 00841062ab73b4f2a573bd2560c9f875e2291fd9 Mon Sep 17 00:00:00 2001 From: Fafnur Date: Thu, 31 Mar 2016 11:05:34 +0600 Subject: [PATCH] fixed edit action --- Controller/ContentBlockController.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Controller/ContentBlockController.php b/Controller/ContentBlockController.php index 0e9c8d9..98c1585 100644 --- a/Controller/ContentBlockController.php +++ b/Controller/ContentBlockController.php @@ -57,7 +57,7 @@ public function createAction($name) { $em = $this->getDoctrine()->getManager(); $repository = $em->getRepository('GlavwebContentBlockBundle:ContentBlock'); - $contentBlock = $repository->findByName($name); + $contentBlock = $repository->findOneByName($name); if(empty($contentBlock)) { $contentBlock = new ContentBlock(); @@ -83,7 +83,7 @@ public function showAction($name) { $em = $this->getDoctrine()->getManager(); $repository = $em->getRepository('GlavwebContentBlockBundle:ContentBlock'); - $contentBlock = $repository->findByName($name); + $contentBlock = $repository->findOneByName($name); if(empty($contentBlock)) { $contentBlock = new ContentBlock(); @@ -91,28 +91,26 @@ public function showAction($name) $contentBlock->setBody($name); $em->persist($contentBlock); $em->flush(); - $status = 200; - } else { - $status = 400; } return new JsonResponse(array( - 'contentBlock' => $contentBlock - ), $status); + 'contentBlock' => $contentBlock->getBody() + )); } /** - * @Route("/api/content-block/{name}/{content}", name="content_block_edit", requirements={"_method": "PUT"}) + * @Route("/api/content-block/{name}", name="content_block_edit", requirements={"_method": "PUT"}) * * @param string $name - * @param string $content + * @param Request $request * @return JsonResponse */ - public function editAction($name, $content) + public function editAction($name, Request $request) { $em = $this->getDoctrine()->getManager(); $repository = $em->getRepository('GlavwebContentBlockBundle:ContentBlock'); - $contentBlock = $repository->findByName($name); + $contentBlock = $repository->findOneByName($name); + $content = $request->request->get('content', ''); if(!empty($contentBlock)) { $contentBlock->setBody($content); @@ -134,7 +132,7 @@ public function removeAction($name) { $em = $this->getDoctrine()->getManager(); $repository = $em->getRepository('GlavwebContentBlockBundle:ContentBlock'); - $contentBlock = $repository->findByName($name); + $contentBlock = $repository->findOneByName($name); if(!empty($contentBlock)) { $em->remove($contentBlock);