Vic*_*sky 6 parameters service dependency-injection symfony
例如,在我的services.yml文件中的下一个代码:
parameters:
social:
facebook:
app_id: 123456789
secret: dkl41a5dw1daw11d1wa135451awwlflaw
google:
id: 12548411654
services:
bw.user.social:
class: BW\UserBundle\Service\SocialService
arguments: [%social.facebook%]
Run Code Online (Sandbox Code Playgroud)
此方法不起作用.我可以用这个:
services:
bw.user.social:
class: BW\UserBundle\Service\SocialService
arguments: [%social%]
Run Code Online (Sandbox Code Playgroud)
但这并不是我所需要的.如何在没有谷歌的情况下仅传递facebook值,这是非常重要的,不是更改参数结构?
你必须这样写你的参数:
parameters:
social.facebook:
app_id: 123456789
secret: dkl41a5dw1daw11d1wa135451awwlflaw
social.google:
id: 12548411654
Run Code Online (Sandbox Code Playgroud)
然后你可以使用:
services:
bw.user.social:
class: BW\UserBundle\Service\SocialService
arguments: [%social.facebook%]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2076 次 |
| 最近记录: |