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

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

hauntd/yii2-vote
================

Votes, likes, favorites.

0.3.3(7y ago)383.1k10[2 issues](https://github.com/hauntd/yii2-vote/issues)BSD-3-ClausePHP

Since Jul 1Pushed 7y ago3 watchersCompare

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

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

Yii2-Vote [![Latest Version](https://camo.githubusercontent.com/d12b6839e73793c5ce528c49ea5bc10ed73829c0889cdf55efca980f5e751ed1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6861756e74642f796969322d766f74652e737667)](https://packagist.org/packages/hauntd/yii2-vote) [![License](https://camo.githubusercontent.com/fa7678944c470698f19f315bfa1b51d912645c7c19c9003ad2be3db75308e2da/68747470733a2f2f706f7365722e707567782e6f72672f6861756e74642f796969322d766f74652f6c6963656e73652e737667)](LICENSE.md) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/f3a2f7db7218d936da32f1982f6934811ca79477e4bf863ef00cc41093359588/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6861756e74642f796969322d766f74652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/hauntd/yii2-vote/?branch=master) [![Code Climate](https://camo.githubusercontent.com/c6901b05f071fa6b1120909be03af9c799c11f2213af27d0505924adff581535/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6861756e74642f796969322d766f74652f6261646765732f6770612e737667)](https://codeclimate.com/github/hauntd/yii2-vote)
============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#yii2-vote----)

This module allows you to attach vote widgets, like/favorite buttons to your models.

[![Demo](https://raw.githubusercontent.com/hauntd/resources/master/yii2-vote/output.gif)](https://raw.githubusercontent.com/hauntd/resources/master/yii2-vote/output.gif)

- Attach as many widgets to model as you need
- Customization (action, events, views)
- Useful widgets included (Favorite button, Like button, Rating "up/down")

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

[](#installation)

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

Either run

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

```

or add

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

```

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

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

[](#configuration)

Add module settings to your application config (`config/main.php`).

Entity names should be in camelCase like `itemVote`, `itemVoteGuests`, `itemLike` and `itemFavorite`.

```
return [
  'modules' => [
    'vote' => [
      'class' => hauntd\vote\Module::class,
        'guestTimeLimit' => 3600,
        'entities' => [
          // Entity -> Settings
          'itemVote' => app\models\Item::class, // your model
          'itemVoteGuests' => [
              'modelName' => app\models\Item::class, // your model
              'allowGuests' => true,
              'allowSelfVote' => false,
              'entityAuthorAttribute' => 'user_id',
          ],
          'itemLike' => [
              'modelName' => app\models\Item::class, // your model
              'type' => hauntd\vote\Module::TYPE_TOGGLE, // like/favorite button
          ],
          'itemFavorite' => [
              'modelName' => app\models\Item::class, // your model
              'type' => hauntd\vote\Module::TYPE_TOGGLE, // like/favorite button
          ],
      ],
    ],
  ],
  'components' => [
    ...
  ]
];
```

After you downloaded and configured `hauntd/yii2-vote`, the last thing you need to do is updating your database schema by applying the migrations:

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

```

Usage
-----

[](#usage)

Vote widget:

```
