PHPackages                             sdailover/yii2-phpsessconnector - 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. sdailover/yii2-phpsessconnector

ActiveYii2-extension

sdailover/yii2-phpsessconnector
===============================

The SDaiLover PHP Session Connector extension for the Yii framework

1.0.0(2y ago)0361BSD-3-ClausePHPPHP &gt;=7.0

Since Mar 4Pushed 2y agoCompare

[ Source](https://github.com/SDaiLover/yii2-phpsessconnector)[ Packagist](https://packagist.org/packages/sdailover/yii2-phpsessconnector)[ GitHub Sponsors](https://github.com/sponsors/sdailover)[ OpenCollective](https://opencollective.com/sdailover)[ RSS](/packages/sdailover-yii2-phpsessconnector/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

 [ ![](https://camo.githubusercontent.com/c193f60b2ee8d81e50f27e434a2ab2e1a3d9bcc3fd1140f9e56aa40f48442917/68747470733a2f2f736461696c6f7665722e6769746875622e696f2f696d616765732f6c6f676f2e706e67) ](https://www.sdailover.com/)

SDaiLover PHPSessionConnector for Yii 2
=======================================

[](#sdailover-phpsessionconnector-for-yii-2)

yii2-phpsessconnector
=====================

[](#yii2-phpsessconnector)

Runtime database helper to choose PHP Session or another database without change structure model of [Yii framework 2.0](https://www.yiiframework.com).

For license information check the [LICENSE](LICENSE.md)-file.

Documentation is at [docs/guide/README.md](docs/guide/README.md).

[![PHP Language](https://camo.githubusercontent.com/f639b35efc8c04a5c7048835665098acab98f09132baf25c595494969fa860ce/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2532304c616e672532302d253230504850253230382e312532302d677261792e7376673f636f6c6f72413d32433533363426636f6c6f72423d304632303237267374796c653d666c6174266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://github.com/sdailover/yii2-phpsessconnector)[![Code Editor](https://camo.githubusercontent.com/4eafe5212b1a6b3c8e2cc30b120b4e0d4fd482655ede8db3e0997d2dae45c686/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2532304944452532302d25323056697375616c253230436f64652532302d677261792e7376673f636f6c6f72413d32433533363426636f6c6f72423d304632303237267374796c653d666c6174266c6f676f3d76697375616c73747564696f266c6f676f436f6c6f723d7768697465)](https://github.com/sdailover/yii2-phpsessconnector)[![PHP Framework](https://camo.githubusercontent.com/968d156bd1f9c90c1096d2b7f2cbeadbc557525c3ae5d56a81fac75fb5a6bbdf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2532304672616d65776f726b2532302d253230596969253230322e302532302d677261792e7376673f636f6c6f72413d32433533363426636f6c6f72423d304632303237267374796c653d666c6174266c6f676f3d6672616d65776f726b266c6f676f436f6c6f723d7768697465)](https://github.com/sdailover/yii2-phpsessconnector)[![CSS Bootstrap](https://camo.githubusercontent.com/44e8067a658d88ac9019861162b899596cb3d02e8709484c4f6006568a40105c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2532304353532532302d253230426f6f747374726170253230352e332532302d677261792e7376673f636f6c6f72413d32433533363426636f6c6f72423d304632303237267374796c653d666c6174266c6f676f3d626f6f747374726170266c6f676f436f6c6f723d7768697465)](https://github.com/sdailover/yii2-phpsessconnector)[![JS jQuery](https://camo.githubusercontent.com/22995046601ec9e74342d12c0ab151add280c9e1c76302d26f383fb4936b2325/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2532304a532532302d2532306a5175657279253230332e322532302d677261792e7376673f636f6c6f72413d32433533363426636f6c6f72423d304632303237267374796c653d666c6174266c6f676f3d6a7175657279266c6f676f436f6c6f723d7768697465)](https://github.com/sdailover/yii2-phpsessconnector)

[![Latest Stable Version](https://camo.githubusercontent.com/ce54e540864021820736fe27161e4473ded9abed5f8bc4778708f90bace0d0ec/68747470733a2f2f706f7365722e707567782e6f72672f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f722f762f737461626c652e706e67)](https://packagist.org/packages/sdailover/yii2-phpsessconnector)[![Total Downloads](https://camo.githubusercontent.com/3e122139488620205a6e1f5432a47be46c23885ad10e273688d1512fcb0ce478/68747470733a2f2f706f7365722e707567782e6f72672f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f722f646f776e6c6f6164732e706e67)](https://packagist.org/packages/sdailover/yii2-phpsessconnector)[![GitHub watchers](https://camo.githubusercontent.com/d8fe470c7a8de6eb51e5d9888eb7c38317dba3af0d88f278d435f7b4fea2cf97/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f72)](https://github.com/sdailover/yii2-phpsessconnector)[![GitHub Repo stars](https://camo.githubusercontent.com/257c197912cfb1d772a55870dc58f413834e51b762b60a2f4fa2a838a50f74d1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f72)](https://github.com/sdailover/yii2-phpsessconnector)[![GitHub issues](https://camo.githubusercontent.com/55c455c5f167252c8cf4d0d79a7df0156f4898f0aef01ad3859b1d637ff9c496/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f72)](https://github.com/sdailover/yii2-phpsessconnector)

[![GitHub contributors](https://camo.githubusercontent.com/2b17f334de1cffbc3a526037b3f8d4896b3cc4188e9f2ea3f8f1dae07520d697/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f72)](https://github.com/sdailover/yii2-phpsessconnector)[![GitHub pull requests](https://camo.githubusercontent.com/d76b39df5dce01a46da072aa78c666caa043eee45a3473804fc86aa4990fbf9a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f72)](https://github.com/sdailover/yii2-phpsessconnector/pulls)[![GitHub issues](https://camo.githubusercontent.com/95e863d6b591d0c1b452f2cd2e3de3d5d3dd7604a554fd78cbff6de5c6fe7602/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f72)](https://github.com/sdailover/yii2-phpsessconnector/issues)[![GitHub Discussions](https://camo.githubusercontent.com/544c1d83039fa9f82106159f1b514380a22cd573c60d415b524b5a8e84224126/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f64697363757373696f6e732f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f72)](https://github.com/sdailover/yii2-phpsessconnector/discussions)[![GitHub last commit (by committer)](https://camo.githubusercontent.com/b37e1b3314ed9831ab0d4ea0e70d357049fdab38b90a708fceed2b60c7e7a1c0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f736461696c6f7665722f796969322d70687073657373636f6e6e6563746f72)](https://github.com/sdailover/yii2-phpsessconnector)

[Report Bug](https://github.com/sdailover/yii2-phpsessconnector/issues/new?assignees=&labels=bug&projects=&template=bug_report.yml)· [Request Feature](https://github.com/sdailover/yii2-phpsessconnector/issues/new?assignees=&labels=enhancement&projects=&template=feature_request.yml)· [Provide Feedback](https://github.com/sdailover/yii2-phpsessconnector/discussions/new?category=ideas&title=Suggest%20for%20SDaiLover%20Yii2%20PhpSessConnector)· [Ask Question](https://github.com/sdailover/yii2-phpsessconnector/discussions/new?category=q-a&title=Ask%20Question%20for%20SDaiLover%20Yii2%20PhpSessConnector)

Love the project? Please consider [donating](https://opencollective.com/sdailover) or give ⭐ to help it improve!

Copyright © ID 2024 SDaiLover ([www.sdailover.com](https://sdailover.com))

All rights reserved.

---

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist sdailover/yii2-phpsessconnector

```

or add

```
"sdailover/yii2-phpsessconnector": "~1.0.0"
```

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

App Configuration
-----------------

[](#app-configuration)

To use this extension, simply add the following code in your application configuration:

```
return [
    //....
    'components' => [
        'db' => [
            'class' => '\sdailover\yii\phpsessconnector\SDConnection',
            'dsn' => 'phpsession:sdailover',
            // prefix name of session
            'tablePrefix' => 'sd_'
        ],
    ],
];
```

Model Usage
-----------

[](#model-usage)

To connect a database using ActiveRecord into a Model class:

```
namespace app\models;

use sdailover\yii\phpsessconnector\SDActiveRecord;

class ModelClass extends SDActiveRecord
{
    //....

    /* Create list attribute or name's field of database. */
    public $attribute;

    /**
     * Default data imported into the php session,
     * this data only load to php session and not
     * import data to real database (mysql, sqlite, others).
     */
    private static $data = [
        [
            'attribute' => 'value',
            //....
        ]
    ];

    /**
     * Set the name of the database table or table session.
     */
    public static function tableName()
    {
        return '{{tablename}}';
    }

    /**
     * Load and import default data to php session.
     */
    public static function loadTable()
    {
        parent::records(static::$data);
    }

    //....
}
```

Provider Usage
--------------

[](#provider-usage)

Data Providers are usually used to search in Models or display Models in the form of widgets such as GridView and other extensions. To implement it into the application created, we can configure it as follows:

```
namespace app\models;

use app\models\ModelClass;
use sdailover\yii\phpsessconnector\SDActiveProvider;

class ModelSearchClass extends ModelClass
{
    //....

    public function search($params)
    {
        $query = ModelClass::find();

        $dataProvider = new SDActiveProvider([
            'query' => $query
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        // Add filter condition
        if ($this->attribute !== null && !empty($this->attribute))
            $query->andFilterWhere(['attribute' => $this->attribute]);
        return $dataProvider;
    }

    //....
}
```

Controller Usage
----------------

[](#controller-usage)

To use the `SDActiveRecord` and `SDDataProvider` that have been created, we can implement them into the Controller that will be used as follows:

```
namespace app\controllers;

use yii\web\Controller;
use app\models\ModelClass;
use app\models\ModelSearchClass;

class SiteController extends Controller
{
    //....

    /**
     * Display model from SDActiveRecord.
     */
    public function actionView()
    {
        $pkId = Yii::$app->request->isGet ? Yii::$app->request->get('attribute') : Yii::$app->request->post('attribute');
        $model = ModelClass::findOne($pkId);

        return $this->render('view', ['model'=>$model]);
    }

    /**
     * Display many model from SDActiveRecord with Data Provider.
     */
    public function actionSearch()
    {
        $searchModel = new ModelSearchClass();
        $searchParams = Yii::$app->request->isGet ? Yii::$app->request->get() : Yii::$app->request->post();
        $dataProvider = $searchModel->search($searchParams);

        return $this->render('search', ['dataProvider'=>$dataProvider]);
    }

    //....
}
```

Support the project
===================

[](#support-the-project)

We open-source almost everything We can and try to reply to everyone needing help using these projects. Obviously, this takes time. You can use this service for free.

If you are using this project and are happy with it or just want to encourage us to continue creating stuff, there are a few ways you can do it:

- Giving proper credit on the GitHub Sponsors page. [![Static Badge](https://camo.githubusercontent.com/9112cfa0039dc822ec6201daf702cbe109e89e4ce24f54c75ee5b365992d5a02/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f25323053706f6e736f722532302d677261792e7376673f636f6c6f72413d45414541454126636f6c6f72423d454145414541267374796c653d666174266c6f676f3d67697468756273706f6e736f7273266c6f676f436f6c6f723d454134414141)](https://github.com/sponsors/sdailover)
- Starring and sharing the project ⭐
- You can make one-time donations via PayPal. I'll probably buy a coffee ☕ or tea 🍵 or cake 🍰
    [![paypal.me/sdailover](https://camo.githubusercontent.com/22194b8a6e1cab08890cff571ec7d5eddcf45d54a28b7b1445724b3033637129/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f253230446f6e6174652532304e6f772532302d677261792e7376673f636f6c6f72413d32433533363426636f6c6f72423d304632303237267374796c653d666f722d7468652d6261646765266c6f676f3d70617970616c266c6f676f436f6c6f723d7768697465)](https://www.paypal.me/sdailover)
- It’s also possible to support mine financially by becoming a backer or sponsor through
    [![opencollective.com/sdailover](https://camo.githubusercontent.com/2ada75acfb829eec28cd201aaed06608d152ed338cfac7b7256f8884fab70a98/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f253230446f6e6174652532304e6f772532302d677261792e7376673f636f6c6f72413d33353543374426636f6c6f72423d323938304239267374796c653d666f722d7468652d6261646765266c6f676f3d6f70656e636f6c6c656374697665266c6f676f436f6c6f723d7768697465)](https://www.opencollective.com/sdailover)

However, we also provide software development services. You can also invite us to collaborate to help your business in developing the software you need. Please contact us at:
[![team@sdailover.com](https://camo.githubusercontent.com/7d10e2032d57e5c9f6f7e2644ca5e7ca98d6bc7c1bd1eacfce8c846e86b8cd21/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f25323053656e642532304d61696c2532302d677261792e7376673f636f6c6f72413d45413433333526636f6c6f72423d393332393145267374796c653d666f722d7468652d6261646765266c6f676f3d676d61696c266c6f676f436f6c6f723d7768697465)](mailto:team@sdailover.com)

🙏 Thanks for your contribute and support! 😍 ❤️
----------------------------------------------

[](#pray-thanks-for-your-contribute-and-support-heart_eyes-heart)

> Any Questions &amp; Other Supports? see [Support](https://github.com/sdailover/.github/blob/master/SUPPORT.md) please.

---

[Visit Website](https://www.sdailover.com)· [Global Issues](https://github.com/sdailover/.github/issues/new/choose)· [Global Discussions](https://github.com/sdailover/.github/discussions)· [Global Wiki](https://github.com/sdailover/.github/wiki)

Copyright © ID 2024 by SDaiLover ([www.sdailover.com](https://sdailover.com))

[![SDaiLover License](https://camo.githubusercontent.com/9982bf7d83e33a08161d86acd3622e5493faaa64d4dfe5c99624d4dcce4a3579/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f7468756d622f312f31382f4273642d6c6963656e73652d69636f6e2d3132307834322e7376672f31323070782d4273642d6c6963656e73652d69636f6e2d3132307834322e7376672e706e67)](https://github.com/sdailover/.github/blob/master/LICENSE.md)

All rights reserved.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

806d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1bfd73ee15d5574db39de82eb2cebf5b57a7758ff0ef8e8c46cf04c7035f80d9?d=identicon)[wiefunkdai](/maintainers/wiefunkdai)

![](https://www.gravatar.com/avatar/63757a022c920a0c98a5a18c5bbe10c77b59e8381aced3366cbc6516268b1b0c?d=identicon)[sdailover](/maintainers/sdailover)

---

Top Contributors

[![wiefunkdai](https://avatars.githubusercontent.com/u/53835042?v=4)](https://github.com/wiefunkdai "wiefunkdai (1 commits)")

---

Tags

active-recordphp-sessionphpsessconnectorsdailoveryii2yii2-extensionConnectionyii2active-recordsdailoverphpsessconnector

### Embed Badge

![Health badge](/badges/sdailover-yii2-phpsessconnector/health.svg)

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

###  Alternatives

[yiisoft/yii2-redis

Redis Cache, Session and ActiveRecord for the Yii framework

48011.7M245](/packages/yiisoft-yii2-redis)[yiisoft/yii2-mongodb

MongoDB extension for the Yii framework

3312.1M45](/packages/yiisoft-yii2-mongodb)[voskobovich/yii2-linker-behavior

This behavior makes it easy to maintain many-to-many and one-to-many relations in your ActiveRecord models.

80319.0k9](/packages/voskobovich-yii2-linker-behavior)[arogachev/yii2-excel

ActiveRecord import and export based on PHPExcel for Yii 2 framework

6480.3k1](/packages/arogachev-yii2-excel)[simialbi/yii2-rest-client

REST client (AR-like model) for Yii Framework 2.0 (via yii2-http-client, extends ApexWire/yii2-restclient)

2232.5k](/packages/simialbi-yii2-rest-client)[arogachev/yii2-sortable

Sortable ActiveRecord for Yii 2 framework

1637.0k4](/packages/arogachev-yii2-sortable)

PHPackages © 2026

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