承接 yeesoft/yii2-yee-settings 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

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 settings table 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 GROUP const 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.php to 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 $modelClass and $viewPath properties 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

Flickr - Yee CMS Settings Module

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2015-07-29