PHPackages                             hunter-kaan/yii2-user-storage - 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. hunter-kaan/yii2-user-storage

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

hunter-kaan/yii2-user-storage
=============================

Simple user storage

1.0.1(8y ago)041MITPHP

Since Feb 15Pushed 8y ago1 watchersCompare

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

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

Yii2 User storage
=================

[](#yii2-user-storage)

Simple storage of user settings, options &amp; etc.

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist hunter-kaan/yii2-user-storage "^1.0"

```

or add

```
"hunter-kaan/yii2-user-storage": "^1.0"

```

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

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

[](#configuration)

To use this extension, you have to configure the `Storage` class in your application configuration:

```
return [
    //....
    'components' => [
        'userStorage' => [
            'class' => HunterKaan\UserStorage\Storage::class,
            'keyPrefix' => '',
            'userStorageTable' => '{{%user_storage}}',
            'userTable' => '{{%user}}',
        ],
    ]
    //....
];
```

Before you can go on you need to create those tables in the database. To do this, you can use the migration stored in `@vendor/hunter-kaan/yii2-user-storage/migrations`:

```
php yii migrate/up --migrationPath=@vendor/hunter-kaan/yii2-user-storage/migrations

```

The component extends the `yii\caching\Cache` class.

A typical usage is like the following:

```
    // To get default form values.
	$formDefaultValues = Yii::$app->userStorage->get('myForm-default-values');

	// To store user choose as default form values.
	$formDefaultValues = ['city_id' => 3];
	Yii::$app->userStorage->set('myForm-options', $formDefaultValues);
```

Examples
--------

[](#examples)

### Model service

[](#model-service)

Store and load model data:

In your controller:

```
    $model = new Post();
    $model->loadDefaultValues();

    // Create model service
    $storageService = Yii::$app->userStorage->buildModelService($model);

    // Load data from user storage to model
    $storageService->load();

    // ...
    if ($model->load(Yii::$app->getRequest()->getBodyParam()) && $model->save()) {
        // Save user data to storage
        $storageService->save();
        // ...
    }
```

The model must implement interface `HunterKaan\UserStorage\UserStorageModelInterface`:

```
class Post extends ActiveRecord implements UserStorageModelInterface
{
    // ...

	/**
	 * Storage safe attributes.
	 *
	 * @return array
	 */
	public function userStorageAttributes()
	{
		return ['pinned'];
	}
	// ...
```

or you must specify safe attributes when loading(saving):

```
    // Create model service
    $storageService = Yii::$app->userStorage->buildModelService($model);

    // Load data from user storage to model
    $storageService->load(null, ['pinned']);
    // ...
    if ($model->load(Yii::$app->getRequest()->getBodyParam()) && $model->save()) {
        // Save user data to storage
        $storageService->save(null, ['pinned']);
        // ...
    }
```

By default model storage key is `YourModel::class`, but it can be redefined:

```
    // Create model service
    $storageService = Yii::$app->userStorage->buildModelService($model);

    // Load data from user storage to model
    $storageService->load(CommonModel::class);
    // ...
    if ($model->load(Yii::$app->getRequest()->getBodyParam()) && $model->save()) {
        // Save user data to storage
        $storageService->save(CommonModel::class);
        // ...
    }
```

Note
----

[](#note)

- Only secure attributes can be saved. [See models guide.](http://www.yiiframework.com/doc-2.0/guide-structure-models.html#safe-attributes)
- If the model does not implement the `UserStorageModelInterface` interface and when loading(saving) does not specify attributes, all safe attributes will be saved.
- At the moment, only storage in the database is supported.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Unknown

Total

1

Last Release

3008d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cb5fcff6dfac91212bf16dd0ffc904b5f3de9bcf98341f3456c28cf3368ce6b5?d=identicon)[hunter-kaan](/maintainers/hunter-kaan)

---

Top Contributors

[![hunter-kaan](https://avatars.githubusercontent.com/u/5260983?v=4)](https://github.com/hunter-kaan "hunter-kaan (4 commits)")

---

Tags

yii2extension

### Embed Badge

![Health badge](/badges/hunter-kaan-yii2-user-storage/health.svg)

```
[![Health](https://phpackages.com/badges/hunter-kaan-yii2-user-storage/health.svg)](https://phpackages.com/packages/hunter-kaan-yii2-user-storage)
```

###  Alternatives

[vyants/yii2-daemon

Extension provides functionality for simple daemons creation and control

7859.0k](/packages/vyants-yii2-daemon)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

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