本文整理匯總了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'));
}