bupy7/yii2-config
最新稳定版本:1.1.0
Composer 安装命令:
composer require bupy7/yii2-config
包简介
This is module allow storing configuration parameters of application to database and management they dynamically from admin panel.
关键字:
README 文档
README
This is module allow storing configuration parameters of application to database and management they dynamically from admin panel.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist bupy7/yii2-config "*"
or add
"bupy7/yii2-config": "*"
to the require section of your composer.json file.
Usage
Added to main application config:
'bootstrap' => [ ... 'config', ... ], 'modules' => [ 'config' => [ 'class' => 'bupy7\config\Module', 'enableCaching' => !YII_DEBUG, 'as access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['admin'], ], ], ], ], ], 'components' => [ 'configManager' => [ 'class' => 'bupy7\config\components\ConfigManager', ], ],
Run migration:
./yii migrate/up --migrationPath=@bupy7/config/migrations
Install demo parameters:
./yii config/init
Config manager allowed by URL:
config/default/index
Adding config parameters
All config parameters necessarily must contain following options:
module(string) - Name of module parameter where it will be use (app, shop, cart, blog, news and etc.).name(string) - Name of parameter (mainPageTitle, adminEmail and etc.).
Module name and name must be unique.
label(string) - Label of parameter. It must be translation message. More info toYii::t().type(integer) - Type of field (bupy7\config\Module::TYPE_INPUT,bupy7\config\Module::TYPE_TEXTand etc). Allowed type field you can see tobupy7\config\Module.rules(array) - Rules of field. All rules must be specified without field name. Example:
'rules' => [ ['required'], ['string', 'max' => 255], ],
More info to bupy7\config\models\Config::afterFind().
Additional options:
language(string) - Language for which this config parameter will be uses ('ru', 'en' and etc). If language isbupy7\config\Module::LANGUAGE_ALLor not set, then this parameter will be uses for all languages. More infoyii\console\Application::$language|yii\web\Application::$language.value(string) - Value of config parameter. By default empty.options(array) - Options depend of field type. More info tobupy7\config\widgets\ActiveForm::field(). Example fortextInputtype:
'options' => [ ['maxlength' => true] ],
hint(string) - Hint of field. It must be translation message. More info toYii::t().
Example configuration parameters:
use bupy7\config\Module as ConfigModule; ... 'modules' => [ ... 'config' => [ 'class' => 'bupy7\config\Module', 'enableCaching' => !YII_DEBUG, 'as access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => ['admin'], ], ], ], 'params' => [ [ 'module' => 'app', 'name' => 'backendSitename', 'label' => 'PARAM_BACKEND_SITENAME', 'value' => 'Backend', 'type' => ConfigModule::TYPE_INPUT, 'language' => 'en', 'rules' => [ ['required'], ['string', 'max' => 255], ], 'options' => [ ['maxlength' => true] ], ], [ 'module' => 'app', 'name' => 'frontendSitename', 'label' => 'PARAM_FRONTEND_SITENAME', 'value' => 'Frontend', 'type' => ConfigModule::TYPE_INPUT, 'language' => 'en', 'rules' => [ ['required'], ['string', 'max' => 255], ], 'options' => [ ['maxlength' => true] ], ], [ 'module' => 'app', 'name' => 'displaySitename', 'label' => 'PARAM_DISPLAY_SITENAME', 'value' => '0', 'type' => ConfigModule::TYPE_YES_NO, 'language' => ConfigModule::LANGUAGE_ALL, 'rules' => [ ['boolean'], ], 'hint' => 'HINT_PARAM_DISPLAY_SITENAME', ], [ 'module' => 'app', 'name' => 'supportEmail', 'label' => 'PARAM_SUPPORT_EMAIL', 'value' => 'support@support.com', 'type' => ConfigModule::TYPE_INPUT, 'language' => ConfigModule::LANGUAGE_ALL, 'rules' => [ ['required'], ['email'], ], ], [ 'module' => 'app', 'name' => 'supportNameEmail', 'label' => 'PARAM_SUPPORT_NAME_EMAIL', 'value' => 'Support of site', 'type' => ConfigModule::TYPE_INPUT, 'language' => 'en', 'rules' => [ ['required'], ['string', 'max' => 255], ], 'options' => [ ['maxlength' => true] ], ], ], ], ... ],
After added configuration parameters run rescan:
./yii config/rescan
Result:
Get value of config parameter
Yii::$app->configManager->get('exampleModuleName', 'exampleParameterName');
If parameter not found, then will be throw exception.
Set value of config parameter
Yii::$app->configManager->set('exampleModuleName', 'exampleParameterName', 'exampleParameterValue');
If parameter not found, then will be throw exception.
Console commands
By default command name equals module name (module name -
configand command name -config).
Initialization the configuration parameters of application with deleting old parameters:
./yii config/init
Adding new and deleting not exists config parameters of application:
./yii config/rescan
After successfully adding/deleting parameters cache will be cleared.
##License
yii2-config is released under the BSD 3-Clause License.
bupy7/yii2-config 适用场景与选型建议
bupy7/yii2-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.64k 次下载、GitHub Stars 达 17, 最近一次更新时间为 2015 年 08 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「module」 「config」 「extension」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bupy7/yii2-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bupy7/yii2-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bupy7/yii2-config 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Zend Framework module to quickly and easily set PHP settings.
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
UI Kit 3 Extension for Yii2
Adds more BBCode
统计信息
- 总下载量: 2.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 17
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-08-02
