PHPackages                             yii2mod/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. yii2mod/yii2-settings

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

yii2mod/yii2-settings
=====================

Yii2 Settings Module

2.5(7y ago)100167.4k↓28.3%32[3 issues](https://github.com/yii2mod/yii2-settings/issues)11MITPHPPHP &gt;=7.1.0CI failing

Since Jun 17Pushed 6y ago9 watchersCompare

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

READMEChangelog (10)Dependencies (5)Versions (27)Used By (11)

 [ ![](https://avatars0.githubusercontent.com/u/993323) ](https://github.com/yiisoft)

Yii2 Settings Extension
=======================

[](#yii2-settings-extension)

Persistent, application-wide settings for Yii2.

[![Latest Stable Version](https://camo.githubusercontent.com/e414b5b497a81631b2cfbac5157ae227a41ee6f6552c9d03f514b3a0d85bc2cb/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d73657474696e67732f762f737461626c65)](https://packagist.org/packages/yii2mod/yii2-settings) [![Total Downloads](https://camo.githubusercontent.com/14ed2ff8a3446414282393e324ef4ef0be52c0a58f1dcc5091ed73b5ac961657/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d73657474696e67732f646f776e6c6f616473)](https://packagist.org/packages/yii2mod/yii2-settings) [![License](https://camo.githubusercontent.com/c4e4d53532513e823cdfdc08f4156bc560ced3d7addf554cdd1859c8fde95a08/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d73657474696e67732f6c6963656e7365)](https://packagist.org/packages/yii2mod/yii2-settings)[![Build Status](https://camo.githubusercontent.com/35e277a435677dca710057a9e689a80c4548ad5bc1ebd1b00c9aca6e2d6397ff/68747470733a2f2f7472617669732d63692e6f72672f796969326d6f642f796969322d73657474696e67732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yii2mod/yii2-settings)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/86b89fb34d29a78b538e001c8de2c35e12624c7b88a097570cef29d8cfe00df9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796969326d6f642f796969322d73657474696e67732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yii2mod/yii2-settings/?branch=master)

Support us
----------

[](#support-us)

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/yii2mod). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

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

[](#installation)

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

Either run

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

or add

```
"yii2mod/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/yii2mod/yii2-settings/migrations
```

**Module Setup**

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

```
'modules' => [
    'settings' => [
        'class' => 'yii2mod\settings\Module',
    ],
],
```

You can then access settings management section through the following URL:

```
http://localhost/path/to/index.php?r=settings

```

or if you have enabled pretty URLs, you may use the following URL:

```
http://localhost/path/to/index.php/settings

```

**Component Setup**

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

```
'components' => [
    'settings' => [
        'class' => 'yii2mod\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();

// Get's all values in the specific section.
$settings->getAllBySection('section');

$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:

```
