示例#1
0
 /**
  * Delete action.
  *
  * @param int|string|null $id
  *
  * @return Response|RedirectResponse
  *
  * @throws NotFoundHttpException If the object does not exist
  * @throws AccessDeniedException If access is not granted
  */
 public function deleteAction($id)
 {
     $id = $this->get('request')->get($this->admin->getIdParameter());
     $object = $this->admin->getObject($id);
     if (!$object) {
         throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
     }
     if (false === $this->admin->isGranted('DELETE', $object)) {
         throw new AccessDeniedException();
     }
     if ($this->getRestMethod() == 'DELETE') {
         // check the csrf token
         $this->validateCsrfToken('sonata.delete');
         try {
             $this->admin->delete($object);
             if ($this->isXmlHttpRequest()) {
                 return $this->renderJson(array('result' => 'ok'));
             }
             $this->addFlash('sonata_flash_success', $this->admin->trans('flash_delete_success', array('%name%' => $this->escapeHtml($this->admin->toString($object))), 'SonataAdminBundle'));
         } catch (ModelManagerException $e) {
             $this->logModelManagerException($e);
             if ($this->isXmlHttpRequest()) {
                 return $this->renderJson(array('result' => 'error'));
             }
             $this->addFlash('sonata_flash_error', $this->admin->trans('flash_delete_error', array('%name%' => $this->escapeHtml($this->admin->toString($object))), 'SonataAdminBundle'));
         }
         return $this->redirectTo($object);
     }
     return $this->render($this->admin->getTemplate('delete'), array('object' => $object, 'action' => 'delete', 'csrf_token' => $this->getCsrfToken('sonata.delete')));
 }
 /**
  * Delete action.
  *
  * @param int|string|null $id
  *
  * @return Response|RedirectResponse
  *
  * @throws NotFoundHttpException If the object does not exist
  * @throws AccessDeniedException If access is not granted
  */
 public function deleteAction($id)
 {
     $request = $this->getRequest();
     $id = $request->get($this->admin->getIdParameter());
     $object = $this->admin->getObject($id);
     if (!$object) {
         throw $this->createNotFoundException(sprintf('unable to find the object with id : %s', $id));
     }
     $this->admin->checkAccess('delete', $object);
     $preResponse = $this->preDelete($request, $object);
     if ($preResponse !== null) {
         return $preResponse;
     }
     if ($this->getRestMethod() == 'DELETE') {
         // check the csrf token
         $this->validateCsrfToken('sonata.delete');
         $objectName = $this->admin->toString($object);
         try {
             $this->admin->delete($object);
             if ($this->isXmlHttpRequest()) {
                 return $this->renderJson(array('result' => 'ok'), 200, array());
             }
             $this->addFlash('sonata_flash_success', $this->admin->trans('flash_delete_success', array('%name%' => $this->escapeHtml($objectName)), 'SonataAdminBundle'));
         } catch (ModelManagerException $e) {
             $this->handleModelManagerException($e);
             if ($this->isXmlHttpRequest()) {
                 return $this->renderJson(array('result' => 'error'), 200, array());
             }
             $this->addFlash('sonata_flash_error', $this->admin->trans('flash_delete_error', array('%name%' => $this->escapeHtml($objectName)), 'SonataAdminBundle'));
         }
         return $this->redirectTo($object);
     }
     return $this->render($this->admin->getTemplate('delete'), array('object' => $object, 'action' => 'delete', 'csrf_token' => $this->getCsrfToken('sonata.delete')), null);
 }
示例#3
0
 public function deleteAction($id)
 {
     $id = $this->get('request')->get($this->admin->getIdParameter());
     $object = $this->admin->getObject($id);
     if (!$object) {
         throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
     }
     $this->admin->delete($object);
     return new RedirectResponse($this->admin->generateUrl('list'));
 }
    public function deleteAction($id)
    {
        if (false === $this->admin->isGranted('DELETE')) {
            throw new AccessDeniedException();
        }

        $id = $this->get('request')->get($this->admin->getIdParameter());
        $object = $this->admin->getObject($id);

        if (!$object) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }

        $this->admin->delete($object);
        $this->get('session')->setFlash('sonata_flash_success', 'flash_delete_success');
        return new RedirectResponse($this->admin->generateUrl('list'));
    }
 /**
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException|\Symfony\Component\Security\Core\Exception\AccessDeniedException
  *
  * @param mixed $id
  *
  * @return Response|RedirectResponse
  */
 public function deleteAction($id)
 {
     $id = $this->get('request')->get($this->admin->getIdParameter());
     $object = $this->admin->getObject($id);
     if (!$object) {
         throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
     }
     if (false === $this->admin->isGranted('DELETE', $object)) {
         throw new AccessDeniedException();
     }
     if ($this->getRequest()->getMethod() == 'DELETE') {
         try {
             $this->admin->delete($object);
             $this->get('session')->setFlash('sonata_flash_success', 'flash_delete_success');
         } catch (ModelManagerException $e) {
             $this->get('session')->setFlash('sonata_flash_error', 'flash_delete_error');
         }
         return new RedirectResponse($this->admin->generateUrl('list'));
     }
     return $this->render('SonataAdminBundle:CRUD:delete.html.twig', array('object' => $object, 'action' => 'delete'));
 }