From 10a8b2374cf29218890bb86e294a0d74c5697417 Mon Sep 17 00:00:00 2001 From: Antonio Mansilla Date: Tue, 19 May 2015 17:58:12 +0200 Subject: [PATCH] [#5272] Fix unexistent controller method --- best_practices/security.rst | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/best_practices/security.rst b/best_practices/security.rst index 06c9e3956eb..ff7e747ae0d 100644 --- a/best_practices/security.rst +++ b/best_practices/security.rst @@ -104,6 +104,10 @@ the security checks in PHP: .. code-block:: php + use Symfony\Component\Security\Core\Exception\AccessDeniedException; + + // ... + /** * @Route("/{id}/edit", name="admin_post_edit") */ @@ -117,7 +121,7 @@ the security checks in PHP: } if (!$post->isAuthor($this->getUser())) { - throw $this->createAccessDeniedException(); + throw new AccessDeniedException(); } // ... @@ -192,6 +196,10 @@ Now, you can use the voter with the ``security.context`` service: .. code-block:: php + use Symfony\Component\Security\Core\Exception\AccessDeniedException; + + // ... + /** * @Route("/{id}/edit", name="admin_post_edit") */ @@ -200,7 +208,7 @@ Now, you can use the voter with the ``security.context`` service: $post = // query for the post ... if (!$this->get('security.context')->isGranted('edit', $post)) { - throw $this->createAccessDeniedException(); + throw new AccessDeniedException(); } }