yeesoft / yii2-comments
Yii2 框架的评论模块
0.1.1
2017-04-16 16:27 UTC
Requires
- tijsverkoyen/akismet: ^1.1
- yiidoc/yii2-timeago: ^2.0
- yiisoft/yii2: ~2.0
This package is auto-updated.
Last update: 2022-03-29 00:25:19 UTC
README
Yii 2 的评论模块
此模块允许您轻松地将评论系统集成到您的 Yii2 应用程序中。
安装
- 运行以下命令之一:
composer require --prefer-dist yeesoft/yii2-comments "~0.1.0"
或者在您的 composer.json
文件的 require 部分添加:
"yeesoft/yii2-comments": "~0.1.0"
到 require 部分中。
- 运行迁移
yii migrate --migrationPath=@vendor/yeesoft/yii2-comments/migrations/
配置
- 在您的配置文件中
'bootstrap' => ['comments'], 'modules'=>[ 'comments' => [ 'class' => 'yeesoft\comments\Comments', ], ],
- 在您模型中 [可选]
public function behaviors() { return [ 'comments' => [ 'class' => 'yeesoft\comments\behaviors\CommentsBehavior' ] ]; }
- 如何启用反垃圾邮件保护(使用 Akismet)[可选]
'modules' => [ 'comments' => [ ... 'enableSpamProtection' => true, ... ], ], 'components' => [ 'akismet' => [ 'class' => 'yeesoft\comments\components\Akismet', 'apiKey' => '*******', //you can get your apiKey here: https://akismet.com/ ], ],
使用方法
- 小部件命名空间
use yeesoft\comments\widgets\Comments;
- 使用 (字符串) 页面密钥在模型视图中添加评论小部件
echo Comments::widget(['model' => $pageKey]);
- 或使用模型名称和 ID 显示评论
echo Comments::widget(['model' => 'post', 'model_id' => 1]);
- 或使用模型行为显示评论
echo Post::findOne(10)->displayComments();
模块选项
使用这些选项来配置评论模块
-
userModel
- 用户模型类名。 -
maxNestedLevel
- 允许的评论回复的最大嵌套级别。 -
onlyRegistered
- 指示未注册用户是否可以发表评论。 -
orderDirection
- 评论排序方向。 -
nestedOrderDirection
- 回复排序方向。 -
userAvatar
- 显示用户头像的字段。如果此字段为 NULL,则将显示默认头像图像。还可以指定图像路径或使用可调用类型。
如果此属性指定为回调,则它应具有以下签名:
function ($user_id)
模块设置示例
'comments' => [ 'class' => 'yeesoft\comments\Comments', 'userAvatar' => function($user_id){ return User::getUserAvatarByID($user_id); } ]