Symfony 3 自己的全局配置文件

Symfony 3 own global configuration file

如何在 symfony 中通过 keys/values 创建和使用自己的全局配置? 我尝试在 parameters 行下的 parameters.yml 中设置 keys/values 安装后在该文件中并像 $pageTitle = $this->getParameter('myKey'); 一样获取它并且它有效但我想要拥有具有结构的整个配置文件例如。 $this->getParameter('myParameters.myKey') 所以:

我创建了新文件:

#app/config/myConfig.yml

myParameters:
    myKey: myValue

我在 config.yml 中添加了:

#app/config/config.yml

imports:
    - { resource: myConfig.yml }

在控制器中:

$pageTitle = $this->getParameter('myKey');

我有例外:

FileLoaderLoadException in FileLoader.php line 118: There is no extension able to load the configuration for "inyconfig" (in....

编辑


此示例有效,但您必须做一点小改动 - myParameters 更改为 parameters,一切都很好。

使用参数代替 myParameters。

所以,输入 app/config/myConfig.yml:

parameters:
    myKey: myValue

您必须进行依赖注入,例如BundleNameDependencieInjection 与您的包相关,然后创建提供配置外部依赖性 and/or 外部配置

的配置 class

去那里看看http://symfony.com/doc/current/bundles/configuration.html#processing-the-configs-array

在参数中,您可以创建一些在某些情况下可以调用的标量或数组变量,在您的情况下,您可以创建一个具有某个范围的数组:

parameters:
# scalar
   one.two.three:    something 
# array
   oneBis:
      twoBis: 
         threeBis:   somethingBis