Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2548,6 +2548,25 @@ the ``ROLE_SUPER_ADMIN`` permission:
}
}

You can pass any controller argument to the #[IsGranted()] attribute by name:

.. code-block:: php-attributes

// src/Controller/PostController.php
// ...

use Symfony\Component\Security\Http\Attribute\IsGranted;

class PostController extends AbstractController
{
#[Route('/posts/{id}/edit', name: 'post_edit')]
#[IsGranted('edit', 'post')]
public function edit(Post $post): Response
{
// ...
}
}

If you want to use a custom status code instead of the default one (which
is 403), this can be done by setting with the ``statusCode`` argument::

Expand Down
2 changes: 2 additions & 0 deletions security/voters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ code like this:
{
#[Route('/posts/{id}', name: 'post_show')]
// check for "view" access: calls all voters
// pass the Post entity by name
#[IsGranted('view', 'post')]
public function show(Post $post): Response
{
Expand All @@ -86,6 +87,7 @@ code like this:

#[Route('/posts/{id}/edit', name: 'post_edit')]
// check for "edit" access: calls all voters
// pass the Post entity by name
#[IsGranted('edit', 'post')]
public function edit(Post $post): Response
{
Expand Down