File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Original file line number Diff line number Diff line change @@ -12,16 +12,23 @@ Security: Complex Access Controls with Expressions
12
12
In addition to a role like ``ROLE_ADMIN ``, the ``isGranted() `` method also
13
13
accepts an :class: `Symfony\\ Component\\ ExpressionLanguage\\ Expression ` object::
14
14
15
+ // src/Controller/MyController.php
16
+ namespace App\Controller;
17
+
18
+ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
15
19
use Symfony\Component\ExpressionLanguage\Expression;
16
- // ...
20
+ use Symfony\Component\HttpFoundation\Response;
17
21
18
- public function index(): Response
22
+ class MyController extends AbstractController
19
23
{
20
- $this->denyAccessUnlessGranted(new Expression(
21
- '"ROLE_ADMIN" in role_names or (not is_anonymous() and user.isSuperAdmin())'
22
- ));
24
+ public function index(): Response
25
+ {
26
+ $this->denyAccessUnlessGranted(new Expression(
27
+ '"ROLE_ADMIN" in role_names or (not is_anonymous() and user.isSuperAdmin())'
28
+ ));
23
29
24
- // ...
30
+ // ...
31
+ }
25
32
}
26
33
27
34
In this example, if the current user has ``ROLE_ADMIN `` or if the current
You can’t perform that action at this time.
0 commit comments