File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -816,19 +816,13 @@ to users that have a specific role.
816
816
Securing Controllers and other Code
817
817
...................................
818
818
819
- You can easily deny access from inside a controller:
820
-
821
- .. versionadded :: 2.6
822
- The ``denyAccessUnlessGranted() `` method was introduced in Symfony 2.6. Previously (and
823
- still now), you could check access directly and throw the ``AccessDeniedException `` as shown
824
- in the example below).
825
-
826
- .. code-block :: php
819
+ You can easily deny access from inside a controller::
827
820
828
821
// ...
829
822
830
823
public function helloAction($name)
831
824
{
825
+ // The second parameter is used to specify on what object the role is tested.
832
826
$this->denyAccessUnlessGranted('ROLE_ADMIN', null, 'Unable to access this page!');
833
827
834
828
// Old way :
@@ -839,6 +833,11 @@ You can easily deny access from inside a controller:
839
833
// ...
840
834
}
841
835
836
+ .. versionadded :: 2.6
837
+ The ``denyAccessUnlessGranted() `` method was introduced in Symfony 2.6. Previously (and
838
+ still now), you could check access directly and throw the ``AccessDeniedException `` as shown
839
+ in the example above).
840
+
842
841
In both cases, a special
843
842
:class: `Symfony\\ Component\\ Security\\ Core\\ Exception\\ AccessDeniedException `
844
843
is thrown, which ultimately triggers a 403 HTTP response inside Symfony.
You can’t perform that action at this time.
0 commit comments