I am using the Symfony security setup. Everything works fine, but I don\'t know how to do one important thing:
In twig, I can reach the current user\'s info by doing
According to the documentation since Symfony 2.1 simply use this shortcut :
$user = $this->getUser();
The above is still working on Symfony 3.2 and is a shortcut for this :
$user = $this->get('security.token_storage')->getToken()->getUser();
The
security.token_storageservice was introduced in Symfony 2.6. Prior to Symfony 2.6, you had to use thegetToken()method of thesecurity.contextservice.
Example : And if you want directly the username :
$username = $this->getUser()->getUsername();
The user will be an object and the class of that object will depend on your user provider.