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

ActiveYii2-extension

chiliec/yii2-vote
=================

Provides anonymous voting for any models

4.3(4mo ago)716.1k30[5 issues](https://github.com/chiliec/yii2-vote/issues)BSD-3-ClausePHPCI passing

Since Jan 2Pushed 4mo ago9 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (16)Used By (0)

Vote for Yii2
=============

[](#vote-for-yii2)

[![Latest Stable Version](https://camo.githubusercontent.com/f00aba6d53fa36cc88c1295ce98db4afe9c85f143d685572da91416df808b998/68747470733a2f2f706f7365722e707567782e6f72672f6368696c6965632f796969322d766f74652f762f737461626c652e737667)](https://packagist.org/packages/chiliec/yii2-vote)[![Total Downloads](https://camo.githubusercontent.com/1c825945c498645f59a3ed76bbb494f85fcab1e4f09b3a925603e49b085e0658/68747470733a2f2f706f7365722e707567782e6f72672f6368696c6965632f796969322d766f74652f646f776e6c6f6164732e737667)](https://packagist.org/packages/chiliec/yii2-vote)[![Tests](https://github.com/chiliec/yii2-vote/actions/workflows/tests.yml/badge.svg)](https://github.com/chiliec/yii2-vote/actions/workflows/tests.yml)[![License](https://camo.githubusercontent.com/d1d4d9565aeae166e47ca13fed72ef93b377ed133c46f157494bfbbe5f85f972/68747470733a2f2f706f7365722e707567782e6f72672f6368696c6965632f796969322d766f74652f6c6963656e73652e737667)](https://packagist.org/packages/chiliec/yii2-vote)

A flexible and easy-to-use voting extension for Yii2 that provides anonymous voting functionality for any ActiveRecord models. Support likes/dislikes with aggregate ratings and guest voting capabilities.

[![How yii2-vote works](https://raw.githubusercontent.com/chiliec/yii2-vote/master/docs/showcase.gif)](https://raw.githubusercontent.com/chiliec/yii2-vote/master/docs/showcase.gif)

Features
--------

[](#features)

- 👍 Like/dislike voting system
- 👤 Guest and authenticated user voting
- 🔄 Optional vote changing
- 📊 Aggregate rating calculations
- 🎨 Customizable widgets
- 🏆 Top-rated models widget
- 🔍 SEO-friendly with rich snippets support
- 💾 Support for MySQL, PostgreSQL, and SQLite

Requirements
------------

[](#requirements)

- PHP 8 or higher
- Yii2 2.0 or higher

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

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

```
composer require chiliec/yii2-vote "^4.3"
```

### Step 2: Configure Your Application

[](#step-2-configure-your-application)

Add the following to your application configuration file (e.g., `config/main.php`):

```
'bootstrap' => [
    'chiliec\vote\components\VoteBootstrap',
],
'modules' => [
    'vote' => [
        'class' => 'chiliec\vote\Module',

        // Display messages in popover (default: false)
        'popOverEnabled' => true,

        // Global settings for all models
        'allowGuests' => true,        // Allow guests to vote (default: true)
        'allowChangeVote' => true,    // Allow users to change their vote (default: true)

        // Register your models
        'models' => [
            // Simple registration
            \common\models\Post::class,

            // With string notation
            'backend\models\Post',

            // With custom ID
            2 => 'frontend\models\Story',

            // With model-specific settings (overrides global settings)
            3 => [
                'modelName' => \backend\models\Mail::class,
                'allowGuests' => false,      // Only authenticated users can vote
                'allowChangeVote' => false,  // Users cannot change their vote
            ],
        ],
    ],
],
```

### Step 3: Run Migrations

[](#step-3-run-migrations)

Apply the database migrations to create the required tables:

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

Usage
-----

[](#usage)

### Basic Vote Widget

[](#basic-vote-widget)

Add the vote widget to your view:

```

```

### Top Rated Widget

[](#top-rated-widget)

Display a list of top-rated models:

```
