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

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

obbz/yii2-vote
==============

Votes, likes, favorites Enchantment

v1.0.2(7y ago)024[1 issues](https://github.com/mattakorn-limkool/yii2-vote/issues)1BSD-3-ClausePHP

Since Oct 23Pushed 6mo agoCompare

[ Source](https://github.com/mattakorn-limkool/yii2-vote)[ Packagist](https://packagist.org/packages/obbz/yii2-vote)[ RSS](/packages/obbz-yii2-vote/feed)WikiDiscussions master Synced today

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

This module allows you to attach vote widgets, like/favorite buttons to your models. This module required obbz/yii2 for core library.

- 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 obbz/yii2-vote "0.3.*"

```

or add

```
"obbz/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 `obbz/yii2-vote`, the last thing you need to do is updating your database schema by applying the migrations:

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

```

Usage
-----

[](#usage)

Vote widget:

```
