yeesoft/yii2-yee-settings
最新稳定版本:0.1.0
Composer 安装命令:
composer require yeesoft/yii2-yee-settings
包简介
Settings Module For Yee CMS
README 文档
README
##Yee CMS - Settings Module
####Module for managing settings
This module is part of Yee CMS (based on Yii2 Framework).
Settings module lets you easily create settings pages. After module installation general settings page will be created. This page contains such options as site title, time format and date format, timezone, etc.
Also you can use setting component. It allows you to get and set settings from application.
Installation
Either run
composer require --prefer-dist yeesoft/yii2-yee-settings "~0.1.0"
or add
"yeesoft/yii2-yee-settings": "~0.1.0"
to the require section of your composer.json file.
Run migrations:
yii migrate --migrationPath=@vendor/yeesoft/yii2-yee-settings/migrations/
Configuration
- In your backend config file
'modules'=>[ 'settings' => [ 'class' => 'yeesoft\settings\SettingsModule', ], ],
- Component settings in common config file
'components'=>[ 'settings' => [ 'class' => 'yeesoft\components\Settings' ], ],
Usage
######Get setting:
You can use array or string with dot notation to separate the group from the key when you try to get some setting.
$setting = Yii::$app->settings->get('general.title');
is equivalent to
$setting = Yii::$app->settings->get('general.title');
######Set setting:
Here you can use the same parameters as in the previous case.
Yii::$app->settings->set('general.title','My Site');
Setting Component Options
Use this options to configurate setting component:
-
cache- the cache object or the application component ID of the cache object. Settings will be cached through this cache object, if it is available. -
cacheKey- key used by the cache component.
Creating own settings page
- Insert into
settingstable your new settings:
INSERT INTO `setting`(`group`,`key`,`value`,`description`) VALUES ('image','width','120','Default images width'), ('image','height','90','Default images height');
- Create settings model for settings group by extending yeesoft\settings\models\BaseSettingsModel class. This model should contain
GROUPconst with settings group name. Also model should contain list of properties with names that match settings name. In model you can specify rules for fields.
namespace backend\models; class ImageSettings extends \yeesoft\settings\models\BaseSettingsModel { const GROUP = 'image'; public $width; public $height; public function rules() { return [ [['width', 'height'], 'required'], [['width', 'height'], 'integer'], ]; } }
- Create view file
backend/views/image-settings/index.phpto display your model form.
use backend\models\ImageSettings; use yeesoft\settings\assets\SettingsAsset; use yii\helpers\Html; use yeesoft\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model backend\models\ImageSetting */ /* @var $form yeesoft\widgets\ActiveForm */ SettingsAsset::register($this); ?> <div class="setting-index"> <h3 class="lte-hide-title page-title">Image Settings</h3> <div class="setting-form"> <?php $form = ActiveForm::begin([ 'id' => 'setting-form', 'validateOnBlur' => false, 'fieldConfig' => [ 'template' => "<div class=\"settings-group\"><div class=\"settings-label\">{label}</div>\n<div class=\"settings-field\">{input}\n{hint}\n{error}</div></div>" ], ]) ?> <?= $form->field($model, 'width')->textInput(['maxlength' => true])->hint($model->getDescription('width')) ?> <?= $form->field($model, 'height')->textInput(['maxlength' => true])->hint($model->getDescription('height')) ?> <?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?> <?php ActiveForm::end(); ?> </div> </div>
- Create settings controller by extending yeesoft\settings\controllers\SettingsBaseController class.
Controller should contain
$modelClassand$viewPathproperties which contain recently created model and view
namespace backend\controllers; class ImageSettingsController extends \yeesoft\settings\controllers\SettingsBaseController { public $modelClass = '\backend\models\ImageSettings'; public $viewPath = '@backend/views/image-settings/index'; }
- Open your settings page:
yoursite.com/admin/image-settings
Screenshots
yeesoft/yii2-yee-settings 适用场景与选型建议
yeesoft/yii2-yee-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.77k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yeesoft/yii2-yee-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yeesoft/yii2-yee-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2015-07-29