How can I pass nested parameter value to service in Symfony2

£可爱£侵袭症+ 提交于 2019-12-10 13:19:55

问题


For example, in my services.yml file next code:

parameters:
    social:
        facebook:
            app_id: 123456789
            secret: dkl41a5dw1daw11d1wa135451awwlflaw
        google:
            id: 12548411654

services:
    bw.user.social:
        class: BW\UserBundle\Service\SocialService
        arguments: [%social.facebook%]

This method does not work. I can use this:

services:
    bw.user.social:
        class: BW\UserBundle\Service\SocialService
        arguments: [%social%]

But it's not exactly what I need. How can I pass only facebook value without google and , it's very important, not change parameters structure?


回答1:


You have to write your parameters like this :

parameters:
    social.facebook:
        app_id: 123456789
        secret: dkl41a5dw1daw11d1wa135451awwlflaw
    social.google:
        id: 12548411654

Then you can use :

services:
    bw.user.social:
        class: BW\UserBundle\Service\SocialService
        arguments: [%social.facebook%]


来源:https://stackoverflow.com/questions/21091629/how-can-i-pass-nested-parameter-value-to-service-in-symfony2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!