本文整理汇总了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')));
}
示例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);
}
示例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'));
}
示例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'));
}
示例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'));
}