定制 justcoded/yii2-settings 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

justcoded/yii2-settings

最新稳定版本:1.0.1

Composer 安装命令:

composer require justcoded/yii2-settings

包简介

Yii2 Settings Component

README 文档

README

993323

Yii2 Settings Extension


Replacement for Yii app params. Easy to use component to store application settings. Supports only DB storage for now. Have ready to use base Settings form model and controller Action.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist justcoded/yii2-settings "*"

or add

"justcoded/yii2-settings": "*"

to the require section of your composer.json.

Configuration

Database migration

Before usage this extension, we'll also need to prepare the database.

You can add migrations path to your console config and then run migrate command:

'migrate' => [
    'migrationPath' => [
        '@vendor/justcoded/yii2-settings/migrations'
    ],
],

or you can run the command below:

php yii migrate --migrationPath=@vendor/justcoded/yii2-settings/migrations

Component Setup

To use the Setting Component, you need to configure the components array in your application configuration:

'components' => [
    'settings' => [
        'class'     => 'justcoded\yii2\settings\components\DbSettings',
    ],
],

and add component name to bootstrap array

    'bootstrap'  => ['log', 'settings'],

Usage

// set value
Yii::$app->settings->set('section_name', 'key', 'value');

// get value
$value = Yii::$app->settings->get('section_name', 'key');

There is a possibility to use models as some setting group object. To do this you have to add modelsMap array to component's configuration:

    'settings' => [
        'class'     => 'justcoded\yii2\settings\components\DbSettings',
        'modelsMap' => [
            'section1' => 'app\models\MySettingsForm1',
            'section2' => 'app\models\MySettingsForm2',
        ],
    ],

Add action to controller to get settings form with keys according to the model's properties

    public function actions()
    {
        return [
            'actionName' => [
                'class' => 'justcoded\yii2\settings\actions\SettingsAction',
                'modelClass' => 'app\models\MySettingsForm1',
            ],
        ];
    }

and create view with some active form. (You can copy a template from extension "views" folder)

Now you can get settings in better way:

$value = Yii::$app->settings->section1->myPropertyName;

This is very useful, if you overwrite Yii/Application classes and specify correct PHPDoc comments. In this way IDE will highlight all sections and properties.

Example

You can check the example on our Yii2 starter kit.

统计信息

  • 总下载量: 3.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 4
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2017-09-22