Symfony:从服务方法注入bundle param配置

时间:2017-07-18 08:58:35

标签: php symfony configuration twig yaml

Symfony新手并尝试配置bundle,通过服务方法调用传递param,但面临错误。 Symfony版本:2.8

 ServiceNotFoundException in
 CheckExceptionOnInvalidReferenceBehaviorPass.php line 58: 
 The service "twig" has a dependency on a non-existent service
 "=service('app.service.myservice').gethellostring()".

目标:将参数从服务方法调用传递到包

示例:

应用程序/配置/ services.yml:

...
    app.service.myService:
        class: AppBundle\Service\MyService

    #for configuration of other service it works perfect, but not for bundle
    app.service.myOtherService:
        class: AppBundle\Service\MyOtherService 
        arguments: ['@=service('app.service.MyService').getHelloString()']


...

应用程序/配置/ config.yml:

...
    twig:
        globals:
            helloString: "@=service('app.service.MyService').getHelloString()"

...

0 个答案:

没有答案