@@ -802,9 +802,6 @@ the ``^``) would match ``/admin/foo`` but would also match URLs like ``/foo/admi
802802
803803 To learn about all of this, see :doc: `/cookbook/security/access_control `.
804804
805- .. _`book-security-securing-controller` :
806-
807-
808805Securing other Services
809806~~~~~~~~~~~~~~~~~~~~~~~
810807
@@ -813,11 +810,15 @@ the one seen in the previous section. For example, suppose you have a service
813810(i.e. a PHP class) whose job is to send emails from one user to another.
814811You can restrict use of this class - no matter where it's being used from -
815812to users that have a specific role.
816- >>>>>>> Minor format improvements
813+
814+ .. _`book-security-securing-controller` :
817815
818816Securing Controllers and other Code
819817...................................
820818
819+ Securing a Controller
820+ ~~~~~~~~~~~~~~~~~~~~~
821+
821822You can easily deny access from inside a controller::
822823
823824 // ...
@@ -835,6 +836,12 @@ You can easily deny access from inside a controller::
835836 The ``security.authorization_checker `` service was introduced in Symfony 2.6. Prior
836837 to Symfony 2.6, you had to use the ``isGranted() `` method of the ``security.context `` service.
837838
839+ .. versionadded :: 2.6
840+ You can use directly :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller::isGranted `
841+ instead of `$this->get('security.context')->isGranted($role) ` to check if
842+ a role is granted and :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller::denyAccessUnlessGranted `
843+ to throw an exception if the access is not granted (like in the example above).
844+
838845.. versionadded :: 2.5
839846 The ``createAccessDeniedException `` method was introduced in Symfony 2.5.
840847
0 commit comments