2013-02-13 25 views
4

我正在寻找创建我自己的yml文件来存储一些全局设置和变量,我可以在我的项目中重新使用它们。我已经在这里搜查,发现另一个答案然而symfony2如何创建自己的自定义yml文件以全局共享?

Set own parameters in 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" 

从阅读错误信息看起来我错过了什么?我是否需要添加某种扩展?

+0

我的问题可能是有用的 - HTTP:// stackoverflow.com/questions/32482622/creating-a-configuration-file-in-symfony2/32502618#32502618 – Peter 2015-09-10 14:26:21

回答

7

最简单的是把你的配置到像参数部分:

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

你也可以处理与自己的分机配置看http://symfony.com/doc/master/book/service_container.html#importing-configuration-via-container-extensions

+0

这工作。获取var我只需要做$ this-> container-> getParameter('something.test') – 2013-02-14 09:43:54

+0

如何从实体内部调用$ this-> container-> getParameter()? – 2013-02-14 15:15:09

+0

您必须将所需的值传递给实体,例如$ report = new Report($ this-> container-> getParameter('something.test'))'或通过setter。您还可以将报告配置为容器中的服务。 – 2013-02-14 20:32:38

相关问题