hauntd/yii2-vote

投票、点赞、收藏。

安装数: 2,766

依赖项: 0

建议者: 0

安全: 0

星标: 39

关注者: 4

分支: 11

开放问题: 2

类型:yii2-extension

0.3.3 2018-10-08 12:25 UTC

This package is auto-updated.

Last update: 2024-09-21 19:47:30 UTC


README

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

Demo

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

安装

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

运行以下命令之一

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

或添加

"hauntd/yii2-vote": "*"

到您的 composer.json 文件的 require 部分。

配置

将模块设置添加到您的应用程序配置(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' => [
    ...
  ]
];

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

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

用法

投票小部件

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

点赞/收藏小部件

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

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

变更日志

请参阅 CHANGELOG 了解最近更改的更多信息。

文档

许可证

BSD 3-Clause License. 请参阅 许可证文件 了解更多信息。