Refilon Refilon - 5 months ago 30
PHP Question

Symfony3 service not found by twig

I've got the following problem. I've got a service. And I want to use that service in every TWIG template. But it does not find my service.

I get the following error:

ServiceNotFoundException in CheckExceptionOnInvalidReferenceBehaviorPass.php line 58:
The service "twig" has a dependency on a non-existent service "appbundle\service\categoryhandler".


Notice that the service is not camelcased, while it is camelcased in my config.yml.

Here's my config.yml part

# Twig Configuration
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
globals:
categories: '@AppBundle\Service\CategoryHandler'


I already added PHP templating engine (found this 'solution' while googling my problem).

templating:
engines: ['twig', 'php']


I've followed this documentation of Symfony

Answer Source

Looks like it cannot find your CategoryHandler service.

Has it been registered? Or, has auto loading been enabled? http://symfony.com/doc/current/service_container.html#creating-configuring-services-in-the-container