Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 164aec4

Browse files
authored
[#13554] Slightly reworded the tip
1 parent 2bc5c54 commit 164aec4

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

security/voters.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,20 @@ in the application, which can be: affirmative, consensus or unanimous.
3131
For more information take a look at
3232
:ref:`the section about access decision managers <components-security-access-decision-manager>`.
3333

34-
The example used throughout this page features just two routes (``post_show`` and ``post_edit``).
35-
However, the main advantage of voters is that you can reuse them in *many* controllers. So if you
36-
really need to secure just one or two routes, you can get away without setting up voters, by
37-
doing the check right inside your controller(s)::
34+
.. tip::
3835

39-
// src/AppBundle/Controller/PostController.php
40-
if ($post->getOwner() !== $this->getUser()) {
41-
throw new AccessDeniedException();
42-
}
36+
The advantage of voters is that you can reuse them in *many* places and centralize
37+
all permission logic. If you don't reuse permissions and the permissions are simple,
38+
you might want to do the check in the controller directly and throw an ``AccessDeniedException``
39+
to create the correct response::
40+
41+
// src/AppBundle/Controller/PostController.php
42+
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
43+
44+
// ...
45+
if ($post->getOwner() !== $this->getUser()) {
46+
throw new AccessDeniedException();
47+
}
4348

4449
The Voter Interface
4550
-------------------

0 commit comments

Comments
 (0)