Giter Club home page Giter Club logo

yii2-settings's Introduction

Yii2 Settings

Latest Stable Version License Yii2

Yii2 settings with database module with GUI manager supported.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require zakharov-andrew/yii2-settings

or add

"zakharov-andrew/yii2-settings": "*"

to the require section of your composer.json file.

Subsequently, run

./yii migrate/up --migrationPath=@vendor/zakharov-andrew/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' => 'ZakharovAndrew\settings\Module',
            'bootstrapVersion' => 5, // if use bootstrap 5
        ],
        // ...
    ],

Add this to your main configuration's components array

    'components' => [
        'settings' => [
            'class' => 'ZakharovAndrew\settings\Settings',
        ],
    ],

Add a new rule for urlManager of your application's configuration file, for example:

'urlManager' => [
    'rules' => [
        'settings' => 'settings/default/index',
        'settings/create' => 'settings/default/create',
        'settings/update' => 'settings/default/update',
        'settings/delete' => 'settings/default/delete',
        'setting-groups/create' => 'settings/setting-groups/create',
        'setting-groups/update' => 'settings/setting-groups/update',
        'setting-groups/delete' => 'settings/setting-groups/delete',
    ],
],

Typical component usage

$settings = Yii::$app->settings;

$valueList = $settings->get('group1');

$value = $settings->get('group1', 'key');

$settings->set('group1', 'key', 'value');

// Automatically called on set();
$settings->clearCache();

License

yii2-settings it is available under a BSD 3-Clause License. Detailed information can be found in the LICENSE.md.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.