简体   繁体   English

树枝找不到Symfony3服务

[英]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. 我想在每个TWIG模板中使用该服务。 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. 请注意,该服务没有被驼峰包装,而在我的config.yml中却被驼峰包装。

Here's my config.yml part 这是我的config.yml部分

# 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 ). 我已经添加了PHP模板引擎( 在搜索我的问题时发现了这个“解决方案” )。

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

I've followed this documentation of Symfony 我遵循了Symfony的这份文档

Looks like it cannot find your CategoryHandler service. 看起来找不到您的CategoryHandler服务。

Has it been registered? 已经注册了吗? Or, has auto loading been enabled? 或者,是否启用了自动加载? http://symfony.com/doc/current/service_container.html#creating-configuring-services-in-the-container http://symfony.com/doc/current/service_container.html#creating-configuring-services-in-the-container

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM