@@ -26,15 +26,22 @@ and ``#[IsGranted()]`` attribute also accept an
26
26
27
27
class MyController extends AbstractController
28
28
{
29
+ #[IsGranted(new Expression('is_granted("ROLE_ADMIN") or is_granted("ROLE_MANAGER")'))]
30
+ public function show(): Response
31
+ {
32
+ // ...
33
+ }
34
+
29
35
#[IsGranted(new Expression(
30
36
'"ROLE_ADMIN" in role_names or (is_authenticated() and user.isSuperAdmin())'
31
37
))]
32
- public function index (): Response
38
+ public function edit (): Response
33
39
{
34
40
// ...
35
41
}
36
42
}
37
- .. code-block :: php-attributes
43
+
44
+ .. code-block :: php
38
45
39
46
// src/Controller/MyController.php
40
47
namespace App\Controller;
@@ -45,25 +52,16 @@ and ``#[IsGranted()]`` attribute also accept an
45
52
46
53
class MyController extends AbstractController
47
54
{
48
- #[IsGranted(new Expression('is_granted("ROLE_ADMIN") or is_granted("ROLE_MANAGER")'))]
49
- public function index(): Response
55
+ public function show(): Response
50
56
{
57
+ $this->denyAccessUnlessGranted(new Expression(
58
+ 'is_granted("ROLE_ADMIN") or is_granted("ROLE_MANAGER")'
59
+ ));
60
+
51
61
// ...
52
62
}
53
- }
54
-
55
- .. code-block :: php
56
-
57
- // src/Controller/MyController.php
58
- namespace App\Controller;
59
63
60
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
61
- use Symfony\Component\ExpressionLanguage\Expression;
62
- use Symfony\Component\HttpFoundation\Response;
63
-
64
- class MyController extends AbstractController
65
- {
66
- public function index(): Response
64
+ public function edit(): Response
67
65
{
68
66
$this->denyAccessUnlessGranted(new Expression(
69
67
'"ROLE_ADMIN" in role_names or (is_authenticated() and user.isSuperAdmin())'
0 commit comments