PHPackages                             kenjebaev/yii2-compare - 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. kenjebaev/yii2-compare

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

kenjebaev/yii2-compare
======================

Compare for Yii2

335PHP

Since Jan 30Pushed 4y ago1 watchersCompare

[ Source](https://github.com/kenjebaev/yii2-compare)[ Packagist](https://packagist.org/packages/kenjebaev/yii2-compare)[ RSS](/packages/kenjebaev-yii2-compare/feed)WikiDiscussions master Synced today

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Yii2 compare
============

[](#yii2-compare)

This extension adds compare for Yii framework 2.0

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

[](#installation)

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

Either run

```
php composer.phar require kenjebaev/yii2-compare"*"

```

or add

```
kenjebaev/yii2-compare: "*"

```

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

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

[](#configuration)

Configure the `compare` component (default values are shown):

```
return [
    //...
    'components' => [
        //...
        'compare' => [
            'class' => 'kenjebaev\compare\Compare',
            'storageClass' => 'kenjebaev\compare\storage\SessionStorage',
            'params' => [
                'key' => 'compare',
                'expire' => 604800,
                'productClass' => 'app\model\Product',
                'productFieldId' => 'id',
            ],
        ],
    ]
    //...
];
```

In addition to `kenjebaev\compare\storage\SessionStorage`, there is also `kenjebaev\compare\storage\CookieStorage` and `kenjebaev\compare\storage\DbSessionStorage`. It is possible to create your own storage, you need to implement the interface `kenjebaev\compare\storage\StorageInterface`.

`DbSessionStorage` uses `SessionStorage` for unauthorized users and database for authorized.

> If you use the `kenjebaev\compare\storage\DbSessionStorage` as `storageClass` then you need to apply the following migration:

```
php yii migrate --migrationPath=@vendor/kenjebaev/yii2-compare/migrations
```

Setting up the `params` array:

- `key` - For Session and Cookie.
- `expire` - Cookie life time.
- `productClass` - Product class is an ActiveRecord model.
- `productFieldId` - Name of the product model `id` field.

Usage
-----

[](#usage)

You can get the compare component anywhere in the app using `Yii::$app->compare`.

Using compare:

```
// Product is an AR model
$product = Product::findOne(1);

// Get component of the compare
$compare = \Yii::$app->compare;

// Add an item to the compare
$compare->add($product);

// Removes an items from the compare
$compare->remove($product->id);

// Removes all items from the compare
$compare->clear();

// Get all items from the compare
$compare->getItems();

// Get an item from the compare
$compare->getItem($product->id);

// Get ids array all items from the compare
$compare->getItemIds();
```

Using compare items:

```
// Product is an AR model
$product = Product::findOne(1);

// Get component of the compare
$compare = \Yii::$app->compare;

// Get an item from the compare
$item = $compare->getItem($product->id);

// Get the id of the item
$item->getId();

// Get the product, AR model
$item->getProduct();
```

> By using method `getProduct()`, you have access to all the properties and methods of the product.

```
$product = $item->getProduct();

echo $product->name;
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 Bus Factor1

Top contributor holds 66.7% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/58163a3dab16ec2140aedc0cf38e58bb912857a777bc334c1cac407c1e56b65a?d=identicon)[kenjebaev](/maintainers/kenjebaev)

---

Top Contributors

[![kenjebaev](https://avatars.githubusercontent.com/u/20373911?v=4)](https://github.com/kenjebaev "kenjebaev (2 commits)")[![mrmuminov](https://avatars.githubusercontent.com/u/64766486?v=4)](https://github.com/mrmuminov "mrmuminov (1 commits)")

### Embed Badge

![Health badge](/badges/kenjebaev-yii2-compare/health.svg)

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

###  Alternatives

[cubear/finder

Finder is a Drupal 8 module to help users find services which meet their criteria

404.2k](/packages/cubear-finder)

PHPackages © 2026

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