PHPackages                             h0rseduck/yii2-settings - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. h0rseduck/yii2-settings

ActiveYii2-extension[File &amp; Storage](/categories/file-storage)

h0rseduck/yii2-settings
=======================

Yii2 Settings Module

2.2.5(6y ago)1227MITPHPPHP &gt;=5.5

Since Jun 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/h0rseduck/yii2-settings)[ Packagist](https://packagist.org/packages/h0rseduck/yii2-settings)[ RSS](/packages/h0rseduck-yii2-settings/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (4)Versions (26)Used By (0)

Yii2 Settings
=============

[](#yii2-settings)

Simple Yii2 settings extension

[![Latest Stable Version](https://camo.githubusercontent.com/aa731d9f5ee21f3e2775bfad7343be92e8d3a9cca4cac7fb6f649eb30e41e24f/68747470733a2f2f706f7365722e707567782e6f72672f68307273656475636b2f796969322d73657474696e67732f762f737461626c65)](https://packagist.org/packages/h0rseduck/yii2-settings) [![Total Downloads](https://camo.githubusercontent.com/005ff7fae34dfe3903fe4fb6178c65874b091ae0b8bd7aedf79265e01ab54e0a/68747470733a2f2f706f7365722e707567782e6f72672f68307273656475636b2f796969322d73657474696e67732f646f776e6c6f616473)](https://packagist.org/packages/h0rseduck/yii2-settings) [![License](https://camo.githubusercontent.com/c0c13cb9c58a61546f43a0affd6b5dc1417fadf867051abb30337dd6275aca03/68747470733a2f2f706f7365722e707567782e6f72672f68307273656475636b2f796969322d73657474696e67732f6c6963656e7365)](https://packagist.org/packages/h0rseduck/yii2-settings)[![Build Status](https://camo.githubusercontent.com/ce30be2819153bad1192a29815c962d46eca1ba68bc3d5749c12a7ae9627eddc/68747470733a2f2f7472617669732d63692e6f72672f68307273656475636b2f796969322d73657474696e67732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/h0rseduck/yii2-settings)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

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

```

or add

```
"h0rseduck/yii2-settings": "*"
```

to the require section of your composer.json.

Configuration
-------------

[](#configuration)

**Database Migrations**

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

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

```

**Module Setup**

To access the module, you need to configure the modules array in your application configuration:

```
'admin' => [
    'modules' => [
        'settings' => [
            'class' => 'h0rseduck\settings\Module',
            // Also you can override some controller properties in following way:
            'controllerMap' => [
                'default' => [
                    'class' => 'h0rseduck\settings\controllers\DefaultController',
                    'searchClass' => [
                        'class' => 'h0rseduck\settings\models\search\SettingSearch',
                        'pageSize' => 25
                    ],
                    'modelClass' => 'Your own model class',
                    'indexView' => 'custom path to index view file',
                    'createView' => 'custom path to create view file',
                    'updateView' => 'custom path to update view file',
                ]
            ]
        ],
    ],
]
```

> You can then access settings page by the following URL:

**Component Setup**

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

```
'components' => [
    'settings' => [
        'class' => 'h0rseduck\settings\components\Settings',
    ],
]
```

Usage:
------

[](#usage)

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

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

$settings->set('section', 'key', 125.5);

$settings->set('section', 'key', 'false', SettingType::BOOLEAN_TYPE);

// Checking existence of setting
$settings->has('section', 'key');

// Activates a setting
$settings->activate('section', 'key');

// Deactivates a setting
$settings->deactivate('section', 'key');

// Removes a setting
$settings->remove('section', 'key');

// Removes all settings
$settings->removeAll();

$settings->invalidateCache(); // automatically called on set(), remove();
```

Manage custom settings
----------------------

[](#manage-custom-settings)

You can use your own form model to manage custom settings for your web application via `SettingsAction`. To use the `SettingsAction` class you need to follow the following steps:

1. Create your own model, for example:

```
