【问题标题】:Symfony3 service not found by twig树枝找不到 Symfony3 服务
【发布时间】: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']

I've followed this documentation of Symfony

【问题讨论】:

  • 你在哪里定义服务@AppBundle\Service\CategoryHandler
  • @dbrumann 无处。那我需要在哪里定义呢?
  • 例如在 services: 下的 config.yml 或导入到 config.yml 的 services.yml 中

标签: php symfony twig


【解决方案1】:

看起来它找不到您的 CategoryHandler 服务。

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

【讨论】:

  • 谢谢,就是这样。由于 dbrumann 在 cmets 中告诉我,我自己才发现它。谢谢你
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多