PHPackages                             yongtiger/yii2-setting - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yongtiger/yii2-setting

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

yongtiger/yii2-setting
======================

Simple and efficient setup. All settings are read from DB or cache into a static array at frontend. Updates specified setting category at backend.

1.2.0(9y ago)1271MITPHPPHP &gt;=5.5

Since Feb 15Pushed 9y ago1 watchersCompare

[ Source](https://github.com/yongtiger/yii2-setting)[ Packagist](https://packagist.org/packages/yongtiger/yii2-setting)[ Docs](http://www.branbook.cc)[ RSS](/packages/yongtiger-yii2-setting/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (6)Used By (1)

Yii2 Setting release version 1.2.0 (CHG# tableName)
===================================================

[](#yii2-setting-release-version-120-chg-tablename)

Simple and efficient setup. All settings are read from DB or cache into a **static array** at frontend. Updates specified setting category at backend.

[![Latest Stable Version](https://camo.githubusercontent.com/b2e5adb803b6d9a61d773475cf2120e48fd20722a08dbf4bb111331c89ccfa7e/68747470733a2f2f706f7365722e707567782e6f72672f796f6e6774696765722f796969322d73657474696e672f762f737461626c65)](https://packagist.org/packages/yongtiger/yii2-setting)[![Total Downloads](https://camo.githubusercontent.com/2bf325477893d56e8048dab9be404d593a6f364502e25abe25a369aa6a78d712/68747470733a2f2f706f7365722e707567782e6f72672f796f6e6774696765722f796969322d73657474696e672f646f776e6c6f616473)](https://packagist.org/packages/yongtiger/yii2-setting)[![Latest Unstable Version](https://camo.githubusercontent.com/336464e19916e432e370e43ddb8d9e1e8b480e005b43791cf14afbf50fe0b74a/68747470733a2f2f706f7365722e707567782e6f72672f796f6e6774696765722f796969322d73657474696e672f762f756e737461626c65)](https://packagist.org/packages/yongtiger/yii2-setting)[![License](https://camo.githubusercontent.com/79a37223070ea812e402e674c4f588d3d9f6ed6fff4bc96a6a8e672fdf3b5174/68747470733a2f2f706f7365722e707567782e6f72672f796f6e6774696765722f796969322d73657474696e672f6c6963656e7365)](https://packagist.org/packages/yongtiger/yii2-setting)

FEATURES
--------

[](#features)

- frontend and backend codes completely **separated**
- settings **pre-stored** in DB
- **categorized** settings
- simple API for frontend read
- displaying all setting items of the specified category by **URL route**
- displaying a setting item according to the specified **input field type**

DEPENDENCES
-----------

[](#dependences)

INSTALLATION
------------

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist yongtiger/yii2-setting "*"

```

or add

```
"yongtiger/yii2-setting": "*"
```

to the require section of your composer.json.

CONFIGURATION
-------------

[](#configuration)

### Database migrations and customize settings

[](#database-migrations-and-customize-settings)

Before usage this extension, you need to prepare the database.

#### 1. Create setting table

[](#1-create-setting-table)

```
php yii migrate --migrationPath=@vendor/yongtiger/yii2-setting/src/migrations

```

#### 2. Customize settings

[](#2-customize-settings)

You need to modify the records in the setting table by any SQL query tools, such as *phpmysqladmin*.

> Refer to `demo settings in DB` and [`Usages`](#usage-in-frontend).

### Backend setup

[](#backend-setup)

#### 1. Module setup

[](#1-module-setup)

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

```
'modules' => [
    // ...
    'setting' => [
        'class' => 'yongtiger\setting\Module',
    ],
    // ...
],
```

#### 2. Internationalization setup (optional)

[](#2-internationalization-setup-optional)

All text and messages introduced in this extension **(NOT include the settings in DB!)** are translatable under category:

```
'extensions/yongtiger/yii2-setting/*'
```

And the default basePath is `'@vendor/yongtiger/yii2-setting/src/messages'`.

If you want to custumize your own translations, using following application configuration:

```
return [
    'components' => [
        'i18n' => [
            'translations' => [
                'extensions/yongtiger/yii2-setting/*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'sourceLanguage' => 'en-US',
                    'basePath' => '',    ///custumize your own translations
                    'fileMap' => [
                        'extensions/yongtiger/yii2-setting/setting' => 'settings.php',
                    ],
                ],
                // ...
            ],
        ],
        // ...
    ],
    // ...
];
```

USAGE IN FRONTEND
-----------------

[](#usage-in-frontend)

> Note: Only `category`, `key`, `value` and `type` fields in the setting table are used in the frontend.

Use function `Setting::get($category, $key, $default = null)` to get a setting directly (no need frontend setup):

```
$mySetting = \yongtiger\setting\Setting::get('site', 'name');
```

The return value has been automatically converted to the type defined in the `setting type`.

See more about `setting type`:

- [`Using basic setting type`](docs/using-basic-setting-type.md)
- [`Using array setting type`](docs/using-array-setting-type.md)
- [`Using object setting type`](docs/using-object-setting-type.md)

### Using default value

[](#using-default-value)

```
///Default value
$mySetting = \yongtiger\setting\Setting::get('not-exist-category', 'not-exist-name', 'default-value');
///Return 'default-value' if no exist setting category or key
```

> Note: It is recommended that `default value` be set to define the type in the `setting type`.

### Using setting array

[](#using-setting-array)

In frontend, while getting any setting for the first time, all settings are read from DB or cache into a **static array**. Later, you can read a setting from the **static array**.

```
$mySettingArray = \yongtiger\setting\Setting::setting;  ///get the current setting array

\yongtiger\setting\Setting::setting = $mySettingArray;  ///dynamically set a setting array
```

### Using caching:

[](#using-caching)

Default caching is enabled.

Sometimes you need to disable the cache (e.g. in testing):

```
\yongtiger\setting\Setting::enableCaching = false;  ///disable caching
$mySetting = \yongtiger\setting\Setting::get('site', 'name');
```

USAGE IN BACKEND
----------------

[](#usage-in-backend)

You can access or update setting page by given the specified `category`:

```
http:///index.php?r=setting/default/update&category=
```

[![Yii-Setting](docs/usage-in-backend.png)](docs/usage-in-backend.png)

See more advanced settings:

- [`Using input field type`](docs/using-input-field-type.md)
- [`Using items and options`](docs/using-items-and-options.md)
- [`Using label and labelOptions`](docs/using-label-and-labeloptions.md)
- [`Using hint and hintOptions`](docs/using-hint-and-hintoptions.md)

TODO
----

[](#todo)

[Development roadmap](docs/development-roadmap.md)
--------------------------------------------------

[](#development-roadmap)

LICENSE
-------

[](#license)

**Yii2-setting** is released under the MIT license, see [LICENSE](https://opensource.org/licenses/MIT) file for details.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

5

Last Release

3337d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4419bd4781ece5b372f87972d5559c6a9ff305d8600fcf99409ce072922b9771?d=identicon)[yongtiger](/maintainers/yongtiger)

---

Tags

configyii2extensionsettingsetup

### Embed Badge

![Health badge](/badges/yongtiger-yii2-setting/health.svg)

```
[![Health](https://phpackages.com/badges/yongtiger-yii2-setting/health.svg)](https://phpackages.com/packages/yongtiger-yii2-setting)
```

###  Alternatives

[lav45/yii2-settings

This extension helps you to easily store and retrieve data for your application.

1615.0k2](/packages/lav45-yii2-settings)[abhi1693/yii2-config

Yii2 manage configuration from database

1311.0k1](/packages/abhi1693-yii2-config)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
