PHPackages                             luckynvic/yii2-option - 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. luckynvic/yii2-option

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

luckynvic/yii2-option
=====================

Yii2 extension to save named value pairs

1.0.0(1y ago)0422BSD-3-ClausePHP

Since Aug 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/luckynvic/yii2-option)[ Packagist](https://packagist.org/packages/luckynvic/yii2-option)[ Docs](https://github.com/luckynvic/yii2-option)[ RSS](/packages/luckynvic-yii2-option/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (6)DependenciesVersions (7)Used By (0)

yii2-option
===========

[](#yii2-option)

Yii2 extension to save named value pairs in database.

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

[](#installation)

Installation is recommended via composer by adding the following to the `require` section in your `composer.json`:

```
"luckynvic/yii2-option": "*"
```

Run `composer update` afterwards.

Run migration following command:

```
	yii migrate --migrationPath="@luckynvic/option/migrations"

```

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

[](#configuration)

Modify your config

```
    'components' => [
        'option' => ['class'=>'\luckynvic\option\components\OptionComponent'],
        ...
	]
```

Usage
-----

[](#usage)

### Saving Option

[](#saving-option)

```
$state_list = [
	'O' => 'Open',
	'P' => 'On Progress',
	'C' => 'Complete',
	'A' => 'Cancel',
];
// save all array value
Yii::$app->option->set('state_list', $state_list);

// add new value or change value
Yii::$app->option->set('state_list', 'Failed', 'F');

// save single value
Yii::$app->option->set('app_name', 'Application Name');
```

### Get Option

[](#get-option)

```
// get all option list
$state_list = Yii::$app->option->get('state_list');
// get all option list with default if not available
$my_list = Yii::$app->option->get('my_list', null, ['this', 'is', 'my', 'list']);

// get only one value
$progress = Yii::$app->option->get('state_list', 'O');
```

**Note:** pass `null` as index will return entire list.

### Delete option

[](#delete-option)

```
// delete entire option
Yii::$app->option->delete('state_list'); // or Yii::$app->option->set('state_list', null);

// delete only one item
Yii::$app->option->delete('state_list', 'C'); // or Yii::$app->option->set('state_list', null, 'C');
```

**Note:** set value to `null` make item will be deleted.

### Context

[](#context)

This extension allow option save based on its context. ie option for User.

```
class User extends  implements IdentityInterface
{
	// add trait
	use \luckynvic\option\traits\HasOption;

	// optional to configure context key
	protected function optionKey()
	{
		return 'user-'.$this->id;
	}

}

// usage in app
$model->findOne(1);
// get user background color for user, default blue
$color = $model->getOption('background', 'color', 'blue');

// set background color to red
$color = $model->setOption('background', 'red', 'color');
```

Author
------

[](#author)

- Lucky Vic ()

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~596 days

Recently: every ~745 days

Total

6

Last Release

622d ago

Major Versions

0.0.5 → 1.0.02024-10-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/47a928ee8a58eaec5ed10e190ef0dc1da23883f8ed00ef699c4e896405aded8e?d=identicon)[luckynvic](/maintainers/luckynvic)

---

Top Contributors

[![luckynvic](https://avatars.githubusercontent.com/u/4830453?v=4)](https://github.com/luckynvic "luckynvic (14 commits)")

---

Tags

optionyii2componentsetting

### Embed Badge

![Health badge](/badges/luckynvic-yii2-option/health.svg)

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

###  Alternatives

[umanskyi31/opengraph

Created a new component for Yii2. The Open Graph component for your website

119.8k](/packages/umanskyi31-opengraph)[dlds/yii2-mlm

Yii2 Multi Level Marketing component

173.8k](/packages/dlds-yii2-mlm)

PHPackages © 2026

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