All Projects → yii2mod → Yii2 Comments

yii2mod / Yii2 Comments

Licence: mit
Comments module for Yii2

Projects that are alternatives of or similar to Yii2 Comments

Yii2 Assets Auto Compress
Automatic compilation of js + css + html
Stars: ✭ 147 (-5.16%)
Mutual labels:  yii2, yii2-extension
Yii2 Wx
这可能是yii2中最好用的微信SDK🔥🔥🔥
Stars: ✭ 148 (-4.52%)
Mutual labels:  yii2, yii2-extension
Yii2 Aws S3
An Amazon S3 component for Yii2
Stars: ✭ 86 (-44.52%)
Mutual labels:  yii2, yii2-extension
Yii2 Schemadump
Generate the schema from an existing database.
Stars: ✭ 78 (-49.68%)
Mutual labels:  yii2, yii2-extension
Yii2 Phone Input
Yii2 International telephone numbers
Stars: ✭ 114 (-26.45%)
Mutual labels:  yii2, yii2-extension
Csv Grid
Yii2 extension for CSV export
Stars: ✭ 83 (-46.45%)
Mutual labels:  yii2, yii2-extension
Yii2fullcalendar
JQuery Fullcalendar Yii2 Extension
Stars: ✭ 120 (-22.58%)
Mutual labels:  yii2, yii2-extension
Yii2 Psr Log Target
Yii 2.0 log target that is able to write messages to PSR-3 compatible logger
Stars: ✭ 58 (-62.58%)
Mutual labels:  yii2, yii2-extension
Ar Position
ActiveRecord behavior, which provides ability for custom records order setup
Stars: ✭ 107 (-30.97%)
Mutual labels:  yii2, yii2-extension
Admin
Admin pack (actions, widgets, etc) for Yii2
Stars: ✭ 100 (-35.48%)
Mutual labels:  yii2, yii2-extension
Yii2 Jwt
JWT implementation for Yii2 Authorization process
Stars: ✭ 61 (-60.65%)
Mutual labels:  yii2, yii2-extension
Yii2 Cart
Yii2 shopping cart
Stars: ✭ 118 (-23.87%)
Mutual labels:  yii2, yii2-extension
Yii2 Collection
Collection extension for Yii 2
Stars: ✭ 62 (-60%)
Mutual labels:  yii2, yii2-extension
Ar Linkmany
ActiveRecord behavior for saving many-to-many relations
Stars: ✭ 83 (-46.45%)
Mutual labels:  yii2, yii2-extension
Sitemap
Site map creation support
Stars: ✭ 59 (-61.94%)
Mutual labels:  yii2, yii2-extension
Yii2 Gallery Manager
Stars: ✭ 90 (-41.94%)
Mutual labels:  yii2, yii2-extension
Config
Yii2 application runtime configuration support
Stars: ✭ 54 (-65.16%)
Mutual labels:  yii2, yii2-extension
Php frameworks analysis
php框架源码分析
Stars: ✭ 57 (-63.23%)
Mutual labels:  yii2, yii2-extension
Yii2 Migrik
Yii2 Gii-tools for create migration files
Stars: ✭ 99 (-36.13%)
Mutual labels:  yii2, yii2-extension
File Storage
File storage abstraction for Yii2
Stars: ✭ 116 (-25.16%)
Mutual labels:  yii2, yii2-extension

Yii2 Comments Extension


This module provides a comments managing system.

Latest Stable Version Total Downloads License Build Status Scrutinizer Code Quality

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 yii2mod/yii2-comments "*"

or add

"yii2mod/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[email protected]vendor/yii2mod/yii2-comments/migrations

Module setup

To access the module, you need to add the following code to your application configuration:

'modules' => [
    'comment' => [
        'class' => 'yii2mod\comments\Module',
    ],
]

NOTE: Module id must be comment and 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 admin role have access to comments management section. But, you can override accessControlConfig property for ManageController.

Notes:

  1. Delete button visible only for users with admin role.
  1. When you delete a comment, all nested comments will be marked as deleted.
  1. You can override default CommentModel class by changing the property commentModelClass in the Comment Module.
  1. You can implement your own methods getAvatar and getUsername in the userIdentityClass. 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 \yii2mod\comments\widgets\Comment::widget([
    'model' => $model,
]); ?>

You can use your own template for render comments:

<?php echo \yii2mod\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 \yii2mod\comments\widgets\Comment::widget([
      'model' => $model,
]); ?>

<?php echo \yii2mod\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 \yii2mod\comments\widgets\Comment::widget([
      'model' => $model,
      'dataProviderConfig' => [
          'pagination' => [
              'pageSize' => 10
          ],
      ]
]); ?>

Advanced example:

<?php echo \yii2mod\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' => 'yii2mod\comments\Module',
        'controllerMap' => [
            'default' => [
                'class' => 'yii2mod\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 'yii2mod.comments'. You may use translations provided within this extension, using following application configuration:

return [
    'components' => [
        'i18n' => [
            'translations' => [
                'yii2mod.comments' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@yii2mod/comments/messages',
                ],
                // ...
            ],
        ],
        // ...
    ],
    // ...
];

Example comments


Alt text

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].