Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Security] Document "pass controller object argument by name" behavior for IsGranted attribute#19858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
PrOF-kk wants to merge1 commit intosymfony:6.4
base:6.4
Choose a base branch
Loading
fromPrOF-kk:6.4
Open
Show file tree
Hide file tree
Changes fromall 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 deletionssecurity.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionssecurity/voters.rst
View file
Open in desktop
Original file line numberDiff line numberDiff 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
Loading

[8]ページ先頭

©2009-2025 Movatter.jp