Skip to content

Commit 994b94f

Browse files
Update expressions.rst
1 parent 70843db commit 994b94f

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

security/expressions.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,22 @@ In addition to a role like ``ROLE_ADMIN``, the ``isGranted()`` method also
1313
accepts an :class:`Symfony\\Component\\ExpressionLanguage\\Expression` object::
1414

1515
// src/Controller/MyController.php
16+
namespace App\Controller;
17+
18+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1619
use Symfony\Component\ExpressionLanguage\Expression;
20+
use Symfony\Component\HttpFoundation\Response;
1721

18-
// ... your controller code
19-
20-
public function index(): Response
22+
class MyController extends AbstractController
2123
{
22-
$this->denyAccessUnlessGranted(new Expression(
23-
'"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
24-
));
24+
public function index(): Response
25+
{
26+
$this->denyAccessUnlessGranted(new Expression(
27+
'"ROLE_ADMIN" in roles or (not is_anonymous() and user.isSuperAdmin())'
28+
));
2529

26-
// ...
30+
// ...
31+
}
2732
}
2833

2934
In this example, if the current user has ``ROLE_ADMIN`` or if the current

0 commit comments

Comments
 (0)