当前位置: 首页>>代码示例>>PHP>>正文


PHP AdminInterface::delete方法代码示例

本文整理汇总了PHP中Sonata\AdminBundle\Admin\AdminInterface::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP AdminInterface::delete方法的具体用法?PHP AdminInterface::delete怎么用?PHP AdminInterface::delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sonata\AdminBundle\Admin\AdminInterface的用法示例。


在下文中一共展示了AdminInterface::delete方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: deleteAction

 /**
  * 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')));
 }
开发者ID:stuckiest,项目名称:SymfonyBlog,代码行数:40,代码来源:CRUDController.php

示例2: deleteAction

 /**
  * 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);
 }
开发者ID:lilocon,项目名称:SonataAdminBundle,代码行数:44,代码来源:CRUDController.php

示例3: deleteAction

 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'));
 }
开发者ID:renegare,项目名称:AdminBundle,代码行数:10,代码来源:CRUDController.php

示例4: deleteAction

    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'));
    }
开发者ID:nibsirahsieu,项目名称:AdminBundle,代码行数:17,代码来源:CRUDController.php

示例5: deleteAction

 /**
  * @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'));
 }
开发者ID:novatex,项目名称:SonataAdminBundle,代码行数:28,代码来源:CRUDController.php


注:本文中的Sonata\AdminBundle\Admin\AdminInterface::delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。