My project runs on symfony 2.3 with fosuserbundle. I want to get the current user in the controller
$securityContext = $this->get('security.context');
$this->currentUser = $securityContext->getToken()->getUser();
and it works if I do it in indexAction()
.
But i need the user in every function of the controller so I tried putting the code in a __construct
function and now it doesn't work anymore.
Why can't I set the variable in a construct function?
Inside the construct function use:
Do not use:
So it should like this: