This module allows you to attach vote widgets, like/favorite buttons to your models.
The preferred way to install this extension is through composer.
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.
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/
Vote widget:
<?= \hauntd\vote\widgets\Vote::widget([
'entity' => 'itemVote',
'model' => $model,
'options' => ['class' => 'vote vote-visible-buttons']
]); ?>
Like/Favorite widgets:
<?= \hauntd\vote\widgets\Favorite::widget([
'entity' => 'itemFavorite',
'model' => $model,
]); ?>
<?= \hauntd\vote\widgets\Like::widget([
'entity' => 'itemLike',
'model' => $model,
]); ?>
Please see CHANGELOG for more information what has changed recently.
BSD 3-Clause License. Please see License File for more information.
fix
Exception thrown when primary key attribute is not 'id' (dronz)enh
JS Events on/off optimization (loveorigami)new
Scope for select only favorite items (loveorigami)fix
Fixes (loveorigami)enh
Self-vote option (sokoji)fix
Migration fix (sokoji)enh
PHP 5.4 Supportenh
Refactoringenh
Auto-detect vote behaviorenh
Visual improvements, loading statenew
Added view params to widgetsnew
Added vote action events (beforeAction, afterAction)new
Ability to exclude default styles (VoteAsset)enh
Visual improvementsenh
Performance improvementsnew
Model and Query behaviorsnew
Favorite widgetnew
Initial release
Comments