pheme/yii2-settings
Composer 安装命令:
composer require pheme/yii2-settings
包简介
Yii2 Database settings
README 文档
README
Yii2 Settings
Yii2 Database settings
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist pheme/yii2-settings "*"
or add
"pheme/yii2-settings": "*"
to the require section of your composer.json file.
Subsequently, run
./yii migrate/up --migrationPath=@vendor/pheme/yii2-settings/migrations
in order to create the settings table in your database.
Usage
There are 2 parts to this extension. A module and a component. The module provides a simple GUI to edit your settings. The component provides a way to retrieve and save settings programmatically.
Add this to your main configuration's modules array
'modules' => [ 'settings' => [ 'class' => 'pheme\settings\Module', 'sourceLanguage' => 'en' ], ... ],
Add this to your main configuration's components array
'components' => [ 'settings' => [ 'class' => 'pheme\settings\components\Settings' ], ... ]
Typical component usage
$settings = Yii::$app->settings; $value = $settings->get('section.key'); $value = $settings->get('key', 'section'); $settings->set('section.key', 'value'); $settings->set('section.key', 'value', null, 'string'); $settings->set('key', 'value', 'section', 'integer'); // Automatically called on set(); $settings->clearCache();
SettingsAction
To use a custom settings form, you can use the included SettingsAction.
- Create a model class with your validation rules.
- Create an associated view with an
ActiveFormcontaining all the settings you need. - Add
pheme\settings\SettingsActionto the controller's actions.
The settings will be stored in section taken from the form name, with the key being the field name.
Model:
class Site extends Model { public $siteName, $siteDescription; public function rules() { return [ [['siteName', 'siteDescription'], 'string'], ]; } public function fields() { return ['siteName', 'siteDescription']; } public function attributes() { return ['siteName', 'siteDescription']; } }
Views:
<?php $form = ActiveForm::begin(['id' => 'site-settings-form']); ?> <?= $form->field($model, 'siteName') ?> <?= $form->field($model, 'siteDescription') ?> <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?> <?php ActiveForm::end(); ?>
Controller:
function actions(){ return [ //.... 'site-settings' => [ 'class' => 'pheme\settings\SettingsAction', 'modelClass' => 'app\models\Site', //'scenario' => 'site', // Change if you want to re-use the model for multiple setting form. //'section' => 'site', // By default use modelClass formname value 'viewName' => 'site-settings' // The form we need to render ], //.... ]; }
pheme/yii2-settings 适用场景与选型建议
pheme/yii2-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 759.69k 次下载、GitHub Stars 达 149, 最近一次更新时间为 2014 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「config」 「Settings」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pheme/yii2-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pheme/yii2-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pheme/yii2-settings 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
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.
Settings Card for Laravel Nova.
Extends basic Wordpress features.
Server environment detection based on config array-file
统计信息
- 总下载量: 759.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 152
- 点击次数: 16
- 依赖项目数: 12
- 推荐数: 2
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-06-20