Skip to content

Commit 40bbd81

Browse files
Explaining controllers as viable alternative
See #13406 (comment)
1 parent e562abf commit 40bbd81

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

security/voters.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ 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)::
38+
39+
// src/AppBundle/Controller/PostController.php
40+
41+
if ($post->getOwner() !== $this->getUser()) {
42+
throw new AccessDeniedException();
43+
}
44+
3445
The Voter Interface
3546
-------------------
3647

0 commit comments

Comments
 (0)