Skip to content

Commit 8a2bbe7

Browse files
authored
[Security] document current user attribute in the main security doc entry
1 parent 570204e commit 8a2bbe7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

security.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,6 +2082,7 @@ accessed via the ``getUser()`` shortcut in the
20822082

20832083
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
20842084
use Symfony\Component\HttpFoundation\Response;
2085+
use Symfony\Component\Security\Http\Attribute\CurrentUser;
20852086

20862087
class ProfileController extends AbstractController
20872088
{
@@ -2100,6 +2101,11 @@ accessed via the ``getUser()`` shortcut in the
21002101
// For example, if you added a getFirstName() method, you can use that.
21012102
return new Response('Well hi there '.$user->getFirstName());
21022103
}
2104+
2105+
public function me(#[CurrentUser] User $user): Response
2106+
{
2107+
// $user is an instance of \App\Entity\User
2108+
}
21032109
}
21042110

21052111
Fetching the User from a Service

0 commit comments

Comments
 (0)