mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 11:36:23 +00:00
29 lines
542 B
Markdown
29 lines
542 B
Markdown
|
---
|
||
|
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)
|
||
|
{
|
||
|
// ...
|
||
|
}
|
||
|
}
|
||
|
```
|