jcabanillas/yii2-comments
Composer 安装命令:
composer require jcabanillas/yii2-comments
包简介
Comments module for Yii2
README 文档
README
Yii2 Comments Extension
This module provides a comments managing system.
Support us
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist jcabanillas/yii2-comments "*"
or add
"jcabanillas/yii2-comments": "*"
to the require section of your composer.json.
Configuration
Database Migrations
Before using Comments Widget, we'll also need to prepare the database.
php yii migrate --migrationPath=@vendor/jcabanillas/yii2-comments/migrations
Module setup
To access the module, you need to add the following code to your application configuration:
'modules' => [ 'comment' => [ 'class' => 'jcabanillas\comments\Module', ], ]
NOTE: Module id must be
commentand not otherwise. This is because it is referred somewhere in the code with such name. A PR to fix it to use configured module id is welcome.
Now you can access to management section through the following URL: http://localhost/path/to/index.php?r=comments/index
By default only users with
adminrole have access to comments management section. But, you can overrideaccessControlConfigproperty for ManageController.
Notes:
- Delete button visible only for users with
adminrole.
- When you delete a comment, all nested comments will be marked as
deleted.
- You can override default CommentModel class by changing the property
commentModelClassin the Comment Module.
- You can implement your own methods
getAvatarandgetUsernamein theuserIdentityClass. Just create this methods in your User model. For example:
public function getAvatar() { // your custom code } public function getUsername() { // your custom code }
Usage
Basic example:
// the model to which are added comments, for example: $model = Post::find()->where(['title' => 'some post title'])->one(); <?php echo \jcabanillas\comments\widgets\Comment::widget([ 'model' => $model, ]); ?>
You can use your own template for render comments:
<?php echo \jcabanillas\comments\widgets\Comment::widget([ 'model' => $model, 'commentView' => '@app/views/site/comments/index' // path to your template ]); ?>
Use the following code for multiple widgets on the same page:
<?php echo \jcabanillas\comments\widgets\Comment::widget([ 'model' => $model, ]); ?> <?php echo \jcabanillas\comments\widgets\Comment::widget([ 'model' => $model2, 'formId' => 'comment-form2', 'pjaxContainerId' => 'unique-pjax-container-id' ]); ?>
To enable the pagination for comments list use the following code:
<?php echo \jcabanillas\comments\widgets\Comment::widget([ 'model' => $model, 'dataProviderConfig' => [ 'pagination' => [ 'pageSize' => 10 ], ] ]); ?>
Advanced example:
<?php echo \jcabanillas\comments\widgets\Comment::widget([ 'model' => $model, 'relatedTo' => 'User ' . \Yii::$app->user->identity->username . ' commented on the page ' . \yii\helpers\Url::current(), 'maxLevel' => 2, 'dataProviderConfig' => [ 'pagination' => [ 'pageSize' => 10 ], ], 'listViewConfig' => [ 'emptyText' => Yii::t('app', 'No comments found.'), ], ]); ?>
Using Events
You may use the following events:
'modules' => [ 'comment' => [ 'class' => 'jcabanillas\comments\Module', 'controllerMap' => [ 'default' => [ 'class' => 'jcabanillas\comments\controllers\DefaultController', 'on beforeCreate' => function ($event) { $event->getCommentModel(); // your custom code }, 'on afterCreate' => function ($event) { $event->getCommentModel(); // your custom code }, 'on beforeDelete' => function ($event) { $event->getCommentModel(); // your custom code }, 'on afterDelete' => function ($event) { $event->getCommentModel(); // your custom code }, ] ] ] ]
Using Comment Plugin Events
$(document).on('beforeCreate', '#comment-form', function (e) { if (!confirm("Everything is correct. Submit?")) { return false; } return true; });
Available events are:
- beforeCreate
- afterCreate
- beforeDelete
- afterDelete
- beforeReply
- afterReply
Internationalization
All text and messages introduced in this extension are translatable under category 'jcabanillas.comments'. You may use translations provided within this extension, using following application configuration:
return [ 'components' => [ 'i18n' => [ 'translations' => [ 'jcabanillas.comments' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@jcabanillas/comments/messages', ], // ... ], ], // ... ], // ... ];
Example comments
jcabanillas/yii2-comments 适用场景与选型建议
jcabanillas/yii2-comments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yii2」 「yii2-comments」 「yii2-comments-module」 「yii2-manage-comments」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jcabanillas/yii2-comments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jcabanillas/yii2-comments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jcabanillas/yii2-comments 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Comments module for Yii2
A custom URL rule class for Yii 2 which allows to create translated URL rules
Comments module for Yii2
Tree comments system
SCEditor, a lightweight WYSIWYG BBCode & HTML editor extension for Yii 2.0 Framework
Redirect all not authenticated web user to login page.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-21