加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

zend-framework2 – 在Zend Framework 2中放置自定义设置的位置?

发布时间:2020-05-31 01:24:04 所属栏目:PHP 来源:互联网
导读:我有一些自定义应用程序特定的设置,我想放入一个配置文件.我在哪里可以放这些?我考虑了/config/autoload/global.php和/或local.php.但我不知道我应该在配置数组中使用哪个键,以确保不会覆盖任何系统设置. 我在想这样的东西(例如在global.php中): return arr

我有一些自定义应用程序特定的设置,我想放入一个配置文件.我在哪里可以放这些?我考虑了/config/autoload/global.php和/或local.php.但我不知道我应该在配置数组中使用哪个键,以确保不会覆盖任何系统设置.

我在想这样的东西(例如在global.php中):

return array(
    'settings' => array(
        'settingA' => 'foo','settingB' => 'bar',),);

这是一个愉快的方式吗?如果是,如何访问设置,例如从控制器内部?

提示非常感激.

如果需要为特定模块创建自定义配置文件,可以在模块/ CustomModule / config文件夹中创建其他配置文件,如下所示:
module.config.php
module.customconfig.php

这是你的module.customconfig.php文件的内容:

return array(
    'settings' => array(
        'settingA' => 'foo',);

那么您需要在CustomModule / module.php文件中更改getConfig()方法:

public function getConfig() {
    $config = array();
    $configFiles = array(
        include __DIR__ . '/config/module.config.php',include __DIR__ . '/config/module.customconfig.php',);
    foreach ($configFiles as $file) {
        $config = ZendStdlibArrayUtils::merge($config,$file);
    }
    return $config;
}

然后您可以在控制器中使用自定义设置:

$config = $this->getServiceLocator()->get('config');
 $settings = $config["settings"];

这对我来说是有效的,希望能帮助你.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读