When I insert security.context into my symfony2 service (twig extension), the following error appears:
Calling the member function getUser () for a non-object .....
class GeninnoShareboardExtension extends \Twig_Extension { public function __construct(ContainerInterface $container, SecurityContext $context) { $this->doctrine = $container->get('doctrine'); $this->context = $context; } public function getUser() { return $this->context->getToken()->getUser(); } ........ }
My services.yml is as follows:
services: geninno.twig.extension.dashboard: class: Geninno\EDSBundle\Twig\Extension\GeninnoShareboardExtension arguments: container: "@service_container" service: "@security.context" tags: - { name: twig.extension }
The user is logged in and my firewall setup looks like this:
access_control: - { path: ^/secured/register, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/secured/create, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/secured/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/, roles: [IS_AUTHENTICATED_FULLY, IS_AUTHENTICATED_REMEMBERED] }
source share