Symfony2在.yml中检索参数时出错

时间:2016-12-02 11:41:29

标签: symfony sonata

当我尝试使用config.yml中定义的参数作为sonata_seo.page.metas.property.fb: app_id的值时,我收到错误消息。如果将此相同参数用作sonata_seo.page.title的值,则一切都按预期工作。

重现的步骤

应用程序/配置/ config.yml

parameters:
    facebook_app_id: 1234567890    
sonata_seo:
    encoding:   UTF-8
    page:
        default:    sonata.seo.page.default
        title:      "%facebook_app_id%" # here receive correctly
        metas:
            property:
                # Facebook application settings
                "fb:app_id":          "%facebook_app_id%" # here broke the code

预期结果

我希望这个HTML标签呈现:

<title>1234567890</title>     
<meta property="fb:app_id" content="1234567890" />

实际结果

php app/console cache:clear --env=prod

结果是:

[Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 4 passed to Sonata\SeoBundle\Seo\SeoPage::addMeta() must be of the type array, null given, called in .../vendor/sonata-project/seo-bundle/Seo/SeoPage.php on line 146 and defined

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

应用程序/配置/ config.yml

parameters:
    facebook_app_id: "1234567890"