tasmaniski/zend-config-helper

此包已被 放弃 并不再维护。作者建议使用 https://github.com/tasmaniski/laminas-config-helper 包。

提供用于读取配置的控制器插件和视图辅助工具。

v3.0.2 2020-04-09 15:45 UTC

This package is auto-updated.

Last update: 2020-11-09 10:53:35 UTC


README

Licence PHP version

IMPORTANT NOTE: 
If you find this package useful, 
please click on a star button and let me know, 
so I will gladly continue with the updates.

Laminas MVC - Config Helper

一个简单小巧的库,用于在所有控制器和视图文件中读取配置数组。

安装

在您的 composer.json 文件中添加

{
    "require": {
        "tasmaniski/laminas-config-helper": "^3.0"
    }
}

运行: composer update 后,您需要注册新模块。在文件 config/application.config.php 中添加

'modules' => array(
    '...',
    'ConfigHelper'
),

使用

您可以在任何控制器或视图文件(包括layout.phtml)中使用它。首先您需要在任何配置文件(config/autoload/*)中添加键,例如 "key_from_config"

//read specific key registred in your config file.
$keyFromConfig = $this->configHelp('key_from_config');

// or in new version of PHP
$keyFromConfig = $this->configHelp()->key_from_config;
$keyFromConfig = $this->configHelp()['key_from_config']; // only for 5.4+

// this will read whole config
$config = $this->configHelp(); // return config object Laminas\Config\Config
echo $config->key_from_config;