You have requested a non-existent service "security.context"
The security.context
service was deprecated in the 2.6 and split into two new services: security.authorization_checker
and security.token_storage
.
Some different usage from the prior version of the framework:
// Symfony 2.5$user = $this->get('security.context')->getToken()->getUser();// Symfony 2.6$user = $this->get('security.token_storage')->getToken()->getUser();// Symfony 2.5if (false === $this->get('security.context')->isGranted('ROLE_ADMIN')) { ... }// Symfony 2.6if (false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN')) { ... }
More info in this announcement
Hope this help
Following example will work:
/*Symfony 4.1.3*/$user = $this->get('security.token_storage')->getToken()->getUser();echo $user->getId(); // USER ID SESSION