如何为此配置我的Twig / Symfony2服务?

时间:2013-03-29 15:49:21

标签: symfony twig

如何为此配置我的服务?

https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Extension/RoutingExtension.php

我猜它是这样的:

  twig.extension.anyName:
    class: Bundle\Twig\RoutingExtension
    arguments:
      - "twig.extension.routing"
    tags:
      - { name: twig.extension }

...但它出错:

Catchable Fatal Error: Argument 1 passed to Bundle\Twig\RoutingExtension::__construct() must implement interface Symfony\Component\Routing\Generator\UrlGeneratorInterface, string given...

1 个答案:

答案 0 :(得分:1)

引用其他服务的有效语法是@符号,后跟服务名称。目前,您正在将字符串“twig.extension.routing”传递给服务构造函数。

如果您希望将服务实例传递给您的服务,它可能看起来像这样

 twig.extension.anyName:
    class: Bundle\Twig\RoutingExtension
    arguments:
      - "@twig.extension.routing"
    tags:
      - { name: twig.extension }