PHPackages                             mhndev/yii2-rate - 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. mhndev/yii2-rate

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mhndev/yii2-rate
================

Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

0.0.5(9y ago)4411[2 issues](https://github.com/mhndev/yii2-rate/issues)MITPHPPHP &gt;=5.4.0

Since Sep 25Pushed 9y ago2 watchersCompare

[ Source](https://github.com/mhndev/yii2-rate)[ Packagist](https://packagist.org/packages/mhndev/yii2-rate)[ RSS](/packages/mhndev-yii2-rate/feed)WikiDiscussions develop Synced today

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

Yii2 Rate functionality implementation
======================================

[](#yii2-rate-functionality-implementation)

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)

    - [Composer](#composer)
- [Configuration](#configuration)

    - [Create Config File](#createconfigfile)
- [Usage](#usage)

    - [Like](#like)
    - [Rate](#rate)

### Yii2 Multi Purpose Rate System (Supports like, dislike, rate with other numbers or text)

[](#yii2-multi-purpose-rate-system-supports-like-dislike-rate-with-other-numbers-or-text)

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

[](#installation)

### Composer

[](#composer)

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

Either run

```
composer require --prefer-dist mhndev/yii2-rate "0.0.*"
```

or add

```
"mhndev/yii2-rate": "0.0.*"
```

### Configuration

[](#configuration)

### create config file

[](#create-config-file)

then of all you need to create a configuration file in your yii2 project config directory called rate.php and fill it like following :

```
return [
    'userClass' => \app\models\User::class,
    'RateClass' => \mhndev\yii2Rate\Models\Rate::class,

    'items'=>[
        'post' => [
            'class'=> \app\models\Post::class,
            'rate_types' => ['rate','like'],
            'rate_values' => [
                'class' => \mhndev\rate\DiscreteNumberValue::class,
                'values' => ['1','2','3','4','5']
            ]
        ]
    ]
];
```

look at config array and check items field are entities which you want to rate them or like them. for example above config array has an item called post. and its fields are :

#### class

[](#class)

which specify entity class which you want to rate

#### rate\_types

[](#rate_types)

you can have multiple kind of rates for an entity for example a user can like a post entity and also rate it

#### rate\_values

[](#rate_values)

you can specify possible rate values for an entity

and after that your user class you should implement following interface

```
mhndev\rate\Interfaces\iUser
```

and add the following method for rate functionality persistence. you can change it as your project needs.

```
    /**
     * @param $value
     * @param iRateableEntity $entity
     * @param $type
     * @return Rate
     */
    public function doRate($value, iRateableEntity $entity, $type)
    {
        $rate = new Rate;

        $rate->type = $type;
        $rate->entity = get_class($entity);
        $rate->entity_id  = $entity->_id->__toString();
        $rate->owner = static::class;
        $rate->owner_id = Yii::$app->user->identity->id;
        $rate->value = $value;

        $rate->save();

        return $rate;
    }
```

Usage
-----

[](#usage)

### Like

[](#like)

This is a sample code which uses this package :

```
    $post = Post::findOne(1);
    $user = Yii::$app->user->identity;
    $user->like($post);
```

### Rate

[](#rate)

```
    $post = Post::findOne(1);
    $user = Yii::$app->user->identity;
    $user->rate(+2, $post, 'rate');
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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

Total

5

Last Release

3551d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5c3e5d182214e2e6b989a2230bcae80b2107b088da1c6dbea6f6f8d28702e272?d=identicon)[majidphpdeveloper](/maintainers/majidphpdeveloper)

---

Top Contributors

[![mhndev](https://avatars.githubusercontent.com/u/5164182?v=4)](https://github.com/mhndev "mhndev (5 commits)")

---

Tags

rateyii2yii2-extensionyii2yiiRatelikedislikeUnlikerank

### Embed Badge

![Health badge](/badges/mhndev-yii2-rate/health.svg)

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

###  Alternatives

[brussens/yii2-maintenance-mode

Maintenance mode component for Yii framework 2.x.x version.

78260.9k5](/packages/brussens-yii2-maintenance-mode)

PHPackages © 2026

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