Php Symfony:从服务方法注入bundle参数配置
Symfony新手,尝试配置bundle,通过服务方法调用传递param,但遇到错误。 Symfony版本:2.8Php Symfony:从服务方法注入bundle参数配置,php,symfony,configuration,twig,yaml,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').geth
ServiceNotFoundException in
CheckExceptionOnInvalidReferenceBehaviorPass.php line 58:
The service "twig" has a dependency on a non-existent service
"=service('app.service.myservice').gethellostring()".
目标:将参数从服务方法调用传递到bundle
例如:
app/config/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()']
...
app/config/config.yml:
...
twig:
globals:
helloString: "@=service('app.service.MyService').getHelloString()"
...
是services.yml app/services.yml吗?如果没有,您是否确定正在处理services.yml文件?从config.yml中注释有问题的行(以克服错误),然后运行bin/console debug:container,查看myService是否显示。Yeap!它们位于app/config/folder中(我可能已经注意到了),是的,它们已经被处理过了。此外,当我将其他服务配置为使用依赖注入参数值时,它可以正常工作。但对Bundle来说不是,我不太会使用表达式。我知道它们适用于服务定义和路由,但我不确定它们是否适用于常规配置。您可能需要设置服务,然后从twig内部调用该方法。我还需要配置其他包,比如为oAuth包设置凭据等等。我需要“配置服务”,将提供第三方的应用程序配置。所以这不仅仅是关于树枝。