PHPackages                             shirase/yii2-vote - 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. shirase/yii2-vote

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

shirase/yii2-vote
=================

Like and dislike module widget

v0.1.1(9y ago)51443[1 issues](https://github.com/AkiraShirase/yii2-vote/issues)BSD-3-ClausePHP

Since Jun 2Pushed 9y ago2 watchersCompare

[ Source](https://github.com/AkiraShirase/yii2-vote)[ Packagist](https://packagist.org/packages/shirase/yii2-vote)[ RSS](/packages/shirase-yii2-vote/feed)WikiDiscussions master Synced 1mo ago

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

likedislike
===========

[](#likedislike)

Like and dislike module widget

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist shirase/yii2-vote "*"

```

or add

```
"shirase/yii2-vote": "*"

```

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

Usage
-----

[](#usage)

Create the table votes using needed type for user and model ID's:

```
CREATE TABLE vote(
	user_id BIGINT NOT NULL,
	model_id BIGINT NOT NULL,
	model VARCHAR(32) NOT NULL,
	type TINYINT(1) NOT NULL,
	ip VARCHAR(15) DEFAULT NULL,
	created_at DATETIME NOT NULL,
	updated_at DATETIME NOT NULL,
	PRIMARY KEY (user_id, model_id, model, type)
);
```

Or use predefined migration in MODULE/migrations folder.

```
php yii migrate --migrationPath=@vendor/shirase/yii2-vote/migrations

```

Include VoteAction in your controller:

```
public function actions()
{
    return [
        'like'=>[
            'class'=>shirase\vote\actions\VoteAction::className(),
            'model'=>shirase\vote\models\Vote::className(),
        ],
        'dislike'=>[
            'class'=>shirase\vote\actions\VoteAction::className(),
            'model'=>shirase\vote\models\Vote::className(),
            'type'=>-1,
        ],
    ];
}
```

VoteAction parameter:
---------------------

[](#voteaction-parameter)

```
"model" - class name of vote activeRecord. Default value: "shirase\vote\models\Like"
"type" - type of operation that will be executed ( 1 => like, -1 => dislike). Default value: 1
"action" - anonymous function that will be called instead of action.
"allowGuests" - allow action for guest users. Default value: false

```

By default client script of voteWidget send "POST" with two parameters for voteAction:

```
"model" - class name for voted model. By default value encoded with crc32.
"id" - ID for voted model.

```

By default VoteAction get next parameters from application:

```
"user_id" - get from Yii::$app->user->id
"ip" - get from Yii::$app->request->userIP

```

Using widget:
-------------

[](#using-widget)

Once the extension is installed, simply use it in your code by :

```
shirase\vote\widgets\Vote::widget([
        'model' => $model, //*Obligatory parameter. Object for Like/Dislike.
        'primaryField' => 'id', //Name of primary key for model
        'actionPath'=>'/controllerName/', //Path to controller for like/dislike action. E.g. '/site/' for action '/site/like'
        'ajaxOptions'=>[
            //ajax attributes
            'url'=>"http://custom.url",
            'method'=>'POST',
            'data'=>['custom'=>'data'],
            'dataType'=>'HTML',
            'etc'=>'etc',
        ],
        'clientOptions'=>[
            //widget attributes
            'likeError'=>JsExpression("alert('like success');"); //method on ajax like error
            'likeSuccess'=>JsExpression("alert('like error');"); //method on ajax like success
            'dislikeSuccess'=>JsExpression("alert('dislike success');"); //method on ajax dislike success
            'dislikeError'=>JsExpression("alert('dislike error');"); //method on ajax dislike error
        ],
        'voteModel' => MyLikeModel::className(), //ActiveRecord class of table for storing vote data.
        'vote' => $myLikeModel, //Vote table object
        'modelField' => 'modelFieldForLikeModel', //Name of field for Vote table in wich store model identifier
        'modelIdField' => 'modelIdFieldForLikeModel', //Name of field for Vote table in wich store model primary key
        'userIdField' => 'userIdFieldForLikeModel', //Name of field for Vote table in wich store user identifier
        'typeField' => 'typeFieldForLikeModel', //Name of field for Vote table in wich store vote type
        'guestErrorMessage' => "You are guest, go away!", //Message displaying instead of widget for guest users
        'cancelable'=>true, //Is user able to cancel their like
    ]);
```

[![Yii2](https://camo.githubusercontent.com/d6b0929173e28cc627430d2519ca1853466a70f37395877eaf4820cb3e1e1909/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f77657265645f62792d5969695f4672616d65776f726b2d677265656e2e7376673f7374796c653d666c6174)](http://www.yiiframework.com/)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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

Total

2

Last Release

3631d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b210336a64d770a4b5fc8c8423ae69550e5ab8655109616a9b65eae1cadf90f0?d=identicon)[AkiraShirase](/maintainers/AkiraShirase)

---

Tags

yii2extensionlikevotedislike

### Embed Badge

![Health badge](/badges/shirase-yii2-vote/health.svg)

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

###  Alternatives

[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)
