I am using symfony2 and FOSUserBundle.
Normally,I can get user data from Controller
$user = $this->get(\'security.context\')->getToken()->g
Be sure to not have the Symfony profiler/toolbar turned on. I don't know why, but that made $this->container->get('security.context')->getToken() return null every time.
Symfony profiler/toolbar
$this->container->get('security.context')->getToken()
null
In the file, config_dev.yml make sure the following is set:
config_dev.yml
web_profiler: toolbar: false