tasmaniski/laminas-config-helper

提供控制器插件和视图助手,用于读取配置。

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

This package is auto-updated.

Last update: 2024-09-09 19:45:14 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 - 配置助手

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

安装

在您的 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;