PHPackages                             platx/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. [Database &amp; ORM](/categories/database)
4. /
5. platx/yii2-settings

AbandonedArchivedYii2-extension[Database &amp; ORM](/categories/database)

platx/yii2-settings
===================

DB settings for Yii2

02.2kPHP

Since Sep 30Pushed 9y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#yii2-settings)

DB settings for Yii2.

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

[](#installation)

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

Either run

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

```

or add

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

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

First, you have to create migration, that creates table for settings.

```
class m000000_000004_create_table_setting extends \platx\settings\CreateSettingTableMigration{}
```

For insert new settings, create migration, that extends from \\platx\\settings\\SettingsMigration and implements parameter protected $\_rows, like this:

```
protected $_rows = [
   [
      self::FIELD_SECTION => 'general',
      self::FIELD_KEY => 'string_setting',
      self::FIELD_NAME => 'String setting',
      self::FIELD_HINT => 'Text setting with max value = 255',
      self::FIELD_VALUE => 'Here some default value of setting',
      self::FIELD_TYPE => Setting::TYPE_TEXT,
      self::FIELD_RULES => [
          ['string', 'max' => 255],
      ]
   ],
   [
      self::FIELD_SECTION => 'general',
      self::FIELD_KEY => 'integer_setting',
      self::FIELD_NAME => 'Integer setting',
      self::FIELD_HINT => 'Setting with integer value',
      self::FIELD_VALUE => '235',
      self::FIELD_TYPE => Setting::TYPE_TEXT,
      self::FIELD_RULES => [
          ['integer', 'max' => 500],
      ]
   ],
   [
      self::FIELD_SECTION => 'general',
      self::FIELD_KEY => 'text_setting',
      self::FIELD_NAME => 'Text setting',
      self::FIELD_HINT => 'Setting with big text value',
      self::FIELD_VALUE => 'some big text',
      self::FIELD_TYPE => Setting::TYPE_TEXTAREA,
      self::FIELD_RULES => [
          ['string'],
      ]
   ],
   [
      self::FIELD_SECTION => 'general',
      self::FIELD_KEY => 'checkbox_setting',
      self::FIELD_NAME => 'Checkbox setting',
      self::FIELD_HINT => 'Checkbox setting with true or false condition',
      self::FIELD_VALUE => '0',
      self::FIELD_TYPE => Setting::TYPE_CHECKBOX,
      self::FIELD_RULES => [
          ['integer'],
      ]
   ],
];
```

For use setting value in your code, try:

```
$settingValue = \platx\settings\Setting::get('section.key');
```

Where `section` - Setting section, `key` - setting key.

For update setting value, use following code:

```
\platx\settings\Setting::set('section.key', 'Here put new value for setting');
```

For update settings for all section, use `\platx\settings\SettingForm` class. Also you can use in your admin controller action `platx\settings\SettingAction` and in your view file you can do something like this:

```
