Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 76d0c72

Browse filesBrowse files
author
Gabriel Birke
committed
How to check for roles in the controller
1 parent e687b74 commit 76d0c72
Copy full SHA for 76d0c72

File tree

Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed

‎book/security/authorization.rst

Copy file name to clipboardExpand all lines: book/security/authorization.rst
+18Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.