5

我正在寻找创建自己的 yml 文件来存储一些可以在我的项目中重复使用的全局设置和变量。我在这里搜索并找到了另一个答案,但它对我不起作用

在 symfony2 中设置自己的参数

我正在寻找添加report_settings.yml文件,以便它在我的项目中自动加载。

这就是我迄今为止所基于的

#app/config/config.yml
imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: report_settings.yml }

 .. rest of config file --

我试图包含的文件看起来像这样

#report_settings.yml
something:
    something1: "test"

它返回以下错误

FileLoaderLoadException: Cannot import resource "/var/www/pcPortal/app/config/report_settings.yml" from "/var/www/pcPortal/app/config/config.yml".

InvalidArgumentException: There is no extension able to load the configuration for "something" (in /var/www/pcPortal/app/config/report_settings.yml). Looked for namespace "something", found "framework", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "jms_aop", "jms_di_extra", "jms_security_extra", "sj_query", "web_profiler", "sensio_distribution"

从阅读错误消息看来我错过了什么?我需要添加某种扩展吗?

4

1 回答 1

7

最简单的方法是将您的配置放入参数部分,例如:

#report_settings.yml
parameters:
    something.something1: "test"

您还可以使用自己的扩展程序处理配置,请参阅http://symfony.com/doc/master/book/service_container.html#importing-configuration-via-container-extensions

于 2013-02-13T19:45:52.190 回答