user2269869
user2269869

Reputation: 191

get the current user in the controller symfony2

I want to get the user currently connected to a session. I mean since we can get the role with this :

$this->get('security.context')->isGranted('ROLE_ADMIN')

could we get the user??

Upvotes: 0

Views: 242

Answers (1)

Vamsi Krishna B
Vamsi Krishna B

Reputation: 11490

you can get the current user like this

$securityContext = $this->get('security.context');
$user = $securityContext->getToken()->getUser();

Upvotes: 3

Related Questions