简体   繁体   English

ZF2 Config:覆盖数组值

[英]ZF2 Config: Overriding array values

Within my module configs in ZF2, I have a few values which are arrays consisting of flags for image manipulation. 在ZF2的模块配置中,我有一些值,这些值是由用于图像处理的标志组成的数组。

I need to be able to override these on a project by project basis, however, when I try to it simply merges the 2 arrays. 我需要能够逐个项目地覆盖它们,但是当我尝试将其简单地合并两个数组时。 Obviously, I can use keys to override that way, however I need to be able to replace the values as a whole as not all the flags would be required on all projects. 显然,我可以使用键来覆盖这种方式,但是我需要能够整体替换这些值,因为并非所有项目都需要所有标志。

Is there a way to completely override a value when it's an array rather than merging the arrays? 有没有一种方法可以完全覆盖一个数组值而不是合并数组?

Cheers 干杯

I need to be able to replace the values as a whole as not all the flags would be required on all projects 我需要能够整体替换值,因为并非所有项目都需要所有标志

If you have multiple installations of ZF2 that share the same module, where they different just in configuration, it would make sense to only define the configuration values that do not differ between projects. 如果您有多个共享同一模块的ZF2安装,但它们的配置只是不同,因此仅定义在项目之间没有区别的配置值将是有意义的。

You would then be set the project specific values within a global config file (eg config/autoload/module.foo-module.global.config ) 然后,您将在全局配置文件(例如config/autoload/module.foo-module.global.config )中设置项目特定的值。

All third-party modules use this method; 所有第三方模块都使用此方法。 for example Doctrine ODM's module.config.php looks like this: 例如,Doctrine ODM的module.config.php如下所示:

return array(
    'doctrine' => array(

        'connection' => array(
            'odm_default' => array(
                'server'           => 'localhost',
                'port'             => '27017',
                'connectionString' => null,
                'user'             => null,
                'password'         => null,
                'dbname'           => null,
                'options'          => array()
            ),
         ),
    ),
);

In each project I would then overwrite (which in your case would be to add) the specific config in module.doctrine-mongo-odm.global.php ) 然后,在每个项目中,我都会覆盖(在您的情况下是要添加) module.doctrine-mongo-odm.global.php的特定配置)

return array(
    'doctrine' => array(

        'connection' => array(
            'odm_default' => array(
                'server'    => '10.0.7.9',
                'dbname'    => 'my_database_name',
                'options'   => array(
                    'foo' => 'bar',
                ),
             ),
        ),
    ),
);

The main difference is that you are not removing config values, but rather adding . 主要区别在于您不是要删除配置值,而是要添加 This makes each of your modules much more reusable. 这使您的每个模块都具有更高的可重用性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM