未找到树枝的Symfony3服务

未找到树枝的Symfony3服务

问题描述:

我遇到以下问题。我有一个服务。我想在每个TWIG模板中使用该服务。但它没有找到我的服务。未找到树枝的Symfony3服务

我得到以下错误:

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

请注意,该服务没有驼峰格式,而它在我的config.yml驼峰格式。

这里是我的config.yml部分

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

我已经加入PHP模板引擎(found this 'solution' while googling my problem)。

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

I've followed this documentation of Symfony

+1

你在哪里定义了服务'@AppBundle \ Service \ CategoryHandler'? – dbrumann

+0

@dbrumann无处。那么我需要在哪里定义它? – Refilon

+1

例如在你的config.yml下的'services:'或在一个services.yml文件中导入到config.yml中 – dbrumann

看起来它找不到你CategoryHandler服务。

它已被注册?或者,自动加载已启用? http://symfony.com/doc/current/service_container.html#creating-configuring-services-in-the-container

+0

谢谢。由于dbrumann在评论中告诉我,我只是自己发现了它。感谢寿 – Refilon