I am using Doctrine as Auth provider in my symfony2 app. How can I access authenticated user in action or template?
In your templates, you can do:
{{ app.user }}
And in your controller, if you extend the base controller provided by the framework bundle, you can do:
$this->getUser();
Anyway, you can access it from the service container:
$securityContext = $container->get('security.context'); $token = $securityContext->getToken(); $user = $token->getUser();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With