Skip to content

Commit 1a041cb

Browse files
committed
Merge pull request #274 from gbirke/authorization_in_controller
How to check for roles in the controller
2 parents de0fc44 + 76d0c72 commit 1a041cb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

book/security/authorization.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,21 @@ syntax:
169169

170170
If you need access to the user from a template, you need to pass it
171171
explicitly.
172+
173+
Access Control in Controllers
174+
-----------------------------
175+
176+
If you want to check a user role in your controller, you use the
177+
``isGranted``method of the security context:
178+
179+
.. code-block:: php
180+
181+
// DefaultController.php
182+
public function indexAction()
183+
{
184+
// show different content to admin users
185+
if($this->get('security.context')->isGranted('ADMIN')) {
186+
// Load admin content here
187+
}
188+
// load other regular content here
189+
}

0 commit comments

Comments
 (0)