2017 © Pedro Peláez
 

yii2-extension yii2-setting

Simple and Configurable Setting rely on DB

image

buddysoft/yii2-setting

Simple and Configurable Setting rely on DB

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 0 % Grown

The README.md

使用数据库存储通用配置项

简介

为 Yii2 封装的一个配置项管理模块。, (*1)

特性:, (*2)

  1. 支持从配置文件读取应用的默认配置项
  2. 支持使用 Yii2 内置的各种 validators 对配置做验证
  3. 内置配置项无法删除,意外删除后会自动用默认配置项填充
  4. 提供配置页面对配置项进行管理

适用环境:, (*3)

  • PHP 5.6 及以上版本
  • Yii2.0.7 及以上版本
  • MySQL 5.6 及以上版本

使用方法

1.安装, (*4)

#composer require buddysoft/yii2-setting

2.导入数据表, (*5)

#cd project_root
#./yii migrate --migrationPath=@buddysoft/setting/migrations

3.创建配置文件, (*6)

示例文件位置: yii2-setting/migrations/settings.php, (*7)

推荐拷贝配置文件到目标应用的 config 目录,以 Yii2 高级模板的 backend 应用为例:, (*8)

#cd project_root
#cp vendor/buddysoft/yii2-setting/migrations/settings.php backend/config/bd_settings.php

导入口,可以对配置项进行修改、添加或删除。, (*9)

4.配置管理页面模块, (*10)

修改 backend/config/main.php, (*11)

// 在文件顶部引入配置文件:

$bdSettings = require(__DIR__ . '/bd_settings.php');

// 在 modules 配置中增加 setting 模块的定义,用到的 bdSettings 变量,就是上面配置的内容。

'modules' => [
    'setting' => [
        'class' => 'buddysoft\setting\Module',
        'defaultSetting' =>  $bdSettings,
    ],
],

经过以上配置,就能在浏览中访问配置界面了:, (*12)

http://localhost/setting/setting/index, (*13)

跟 Yii2-admin 配合使用时,记得将 setting/setting/* 访问权限添加给用户。, (*14)

5.在代码中使用配置项, (*15)

use buddysoft/setting/SettingHelper;
// 'sms-switch' 就是配置项的 key 值。
$intValue = SettingHelper::intValue('sms-switch');

配置项定义方法

示例:, (*16)

[
    'name' => '短信通道开关',
    'key' => 'sms-switch',
    'value' => '1', // 默认值
    'weight' => '0', // 后台配置界面显示顺序
    'description' => '是否打开短信验证,打开后...',
    'options' => [
        'validator' => 'in',
        'params' => [
            'range' => ['1', '0']
        ]
    ],
],

配置中使用 options 配置 validator 对 value 的合法性进行验证。, (*17)

options 有两个属性:, (*18)

  • validator:配置项名字,诸如 integer, string, in 等
  • params: validator 验证时使用的参数,参考 validators 的 public 属性

分类功能

为了方便在后台管理所有配置项,所以给配置项增加了分类(category)属性,后台展示时,同一分类的配置项在一个 Tab 中展示。, (*19)

注意:配置项不会根据分类进行隔离,所有配置项都在同一名字空间中。, (*20)

The Versions

06/02 2018

dev-master

9999999-dev https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

06/02 2018

v1.2.4

1.2.4.0 https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

09/01 2018

v1.2.3

1.2.3.0 https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

08/01 2018

v1.2.2

1.2.2.0 https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

15/06 2017

v1.2.1

1.2.1.0 https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

14/06 2017

v1.2.0

1.2.0.0 https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

08/06 2017

v1.1.0

1.1.0.0 https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

08/06 2017

v1.0.4

1.0.4.0 https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

08/06 2017

v1.0.3

1.0.3.0 https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

05/06 2017

v1.0.2

1.0.2.0 https://github.com/liuwanwei/yii2-setting

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires

 

05/06 2017

v1.0.1

1.0.1.0 https://github.com/liuwanwei/yii2-module

Simple and Configurable Setting rely on DB

  Sources   Download

Apache Version 2.0

The Requires