obbz/yii2-vote

投票,点赞,收藏功能

安装次数: 24

依赖者: 1

建议者: 0

安全性: 0

类型:yii2-extension

v1.0.2 2018-10-29 07:42 UTC

This package is auto-updated.

Last update: 2024-09-04 07:39:32 UTC


README

此模块允许您将投票小部件、点赞/收藏按钮附加到您的模型上。

  • 根据需要将尽可能多的小部件附加到模型上
  • 自定义(操作、事件、视图)
  • 包含有用的小部件(收藏按钮、点赞按钮、评分“上下”)

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一:

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

或将以下内容添加到您的 composer.json 文件的 require 部分。

"obbz/yii2-vote": "*"

配置

将模块设置添加到您的应用程序配置文件中(config/main.php)。

实体名称应使用驼峰式命名法,例如 itemVoteitemVoteGuestsitemLikeitemFavorite

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' => [
    ...
  ]
];

在您下载并配置了 obbz/yii2-vote 之后,您需要做的最后一件事是通过应用迁移来更新您的数据库模式

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

使用方法

投票小部件

<?= \obbz\vote\widgets\Vote::widget([
  'entity' => 'itemVote',
  'model' => $model,
  'options' => ['class' => 'vote vote-visible-buttons']
]); ?>

点赞/收藏小部件

<?= \obbz\vote\widgets\Favorite::widget([
    'entity' => 'itemFavorite',
    'model' => $model,
]); ?>

<?= \obbz\vote\widgets\Like::widget([
    'entity' => 'itemLike',
    'model' => $model,
]); ?>

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

文档

许可

BSD 3-Clause License。有关更多信息,请参阅 许可文件