【发布时间】:2017-07-02 19:21:56
【问题描述】:
我遇到了以下问题。我有服务。我想在每个 TWIG 模板中使用该服务。但它没有找到我的服务。
我收到以下错误:
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']
【问题讨论】:
-
你在哪里定义服务
@AppBundle\Service\CategoryHandler? -
@dbrumann 无处。那我需要在哪里定义呢?
-
例如在
services:下的 config.yml 或导入到 config.yml 的 services.yml 中