I have this code in controller
public function newAction()
{
$em = $this->getDoctrine()->getEntityManager();
$user = $this->container->get('security.context')->getToken()->getUser();
I am getting this error
Fatal error: Call to a member function getUser() on a non-object in
/home/xxxxx/Acme/UserBundle/Controller/UserController.php on line 86
It means that your security context was not populated with token. It happens, when route to your action is not behind the firewall.
You should check your firewall pattern in
security.yml