wiki/content/20201117102746-currentuser.md

30 lines
559 B
Markdown
Raw Permalink Normal View History

2024-05-06 20:40:05 +00:00
---
2024-10-30 17:34:11 +00:00
date: 2020-11-17
2024-05-06 20:40:05 +00:00
id: 7fb18668-63f0-405f-be7e-67a4ef18e6f4
title: CurrentUser
---
# Description
Turns controller argument into the object that represents the currently
logged in user.
# Syntax
``` php
// src/Controller/SomeController.php
namespace App\Controller;
use App\Entity\MyUser;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Http\Attribute\CurrentUser;
class SomeController extends AbstractController
{
public function index(#[CurrentUser] MyUser $user)
{
// ...
}
}
```