2017 © Pedro Peláez
 

yii2-extension yii2-comments

Comments module for Yii2

image

yii2mod/yii2-comments

Comments module for Yii2

  • Saturday, October 7, 2017
  • by disem
  • Repository
  • 23 Watchers
  • 121 Stars
  • 12,178 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 49 Forks
  • 3 Open issues
  • 39 Versions
  • 7 % Grown

The README.md

, (*1)

Yii2 Comments Extension


This module provides a comments managing system., (*2)

Latest Stable Version Total Downloads License Build Status Scrutinizer Code Quality, (*3)

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., (*4)

Installation

The preferred way to install this extension is through composer., (*5)

Either run, (*6)

php composer.phar require --prefer-dist yii2mod/yii2-comments "*"

or add, (*7)

"yii2mod/yii2-comments": "*"

to the require section of your composer.json., (*8)

Configuration

Database Migrations, (*9)

Before using Comments Widget, we'll also need to prepare the database., (*10)

php yii migrate --migrationPath=@vendor/yii2mod/yii2-comments/migrations

Module setup, (*11)

To access the module, you need to add the following code to your application configuration:, (*12)

'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., (*13)

Now you can access to management section through the following URL: http://localhost/path/to/index.php?r=comments/index, (*14)

By default only users with admin role have access to comments management section. But, you can override accessControlConfig property for ManageController., (*15)

Notes:, (*16)

1) Delete button visible only for users with admin role., (*17)

2) When you delete a comment, all nested comments will be marked as deleted., (*18)

3) You can override default CommentModel class by changing the property commentModelClass in the Comment Module., (*19)

4) You can implement your own methods getAvatar and getUsername in the userIdentityClass. Just create this methods in your User model. For example:, (*20)


public function getAvatar() { // your custom code } public function getUsername() { // your custom code }

Usage

Basic example:, (*21)

// the model to which are added comments, for example:
$model = Post::find()->where(['title' => 'some post title'])->one();

 $model,
]); ?>

You can use your own template for render comments:, (*22)

php <?php echo \yii2mod\comments\widgets\Comment::widget([ 'model' => $model, 'commentView' => '@app/views/site/comments/index' // path to your template ]); ?>, (*23)

Use the following code for multiple widgets on the same page: ```php $model, ]); ?>, (*24)

$model2, 'formId' => 'comment-form2', 'pjaxContainerId' => 'unique-pjax-container-id' ]); ?> ```, (*25)

To enable the pagination for comments list use the following code:, (*26)

 $model,
      'dataProviderConfig' => [
          'pagination' => [
              'pageSize' => 10
          ],
      ]
]); ?>

Advanced example:, (*27)

<?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:, (*28)

'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:, (*29)

  • 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:, (*30)

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

#### Example comments

Alt text, (*31)

The Versions

07/10 2017

dev-master

9999999-dev

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

27/04 2017

1.9.9.2

1.9.9.2

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

24/04 2017

1.9.9.1

1.9.9.1

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

16/04 2017

1.9.9

1.9.9.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

12/04 2017

1.9.8

1.9.8.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

14/03 2017

dev-update_test_case

dev-update_test_case

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

18/02 2017

1.9.7

1.9.7.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

31/01 2017

1.9.6

1.9.6.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

29/01 2017

1.9.5

1.9.5.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

28/01 2017

1.9.4

1.9.4.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

13/01 2017

1.9.3

1.9.3.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

06/01 2017

1.9.2

1.9.2.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

06/01 2017

1.9.1

1.9.1.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

05/12 2016

1.9

1.9.0.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 yii2-comments yii2-comments-module yii2-manage-comments

22/11 2016

1.8.2

1.8.2.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

extension yii2

22/11 2016

1.8.1

1.8.1.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

extension yii2

14/11 2016
11/11 2016
11/11 2016

1.6.2

1.6.2.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

09/11 2016

1.6.1

1.6.1.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

09/11 2016
08/11 2016
06/11 2016
03/08 2016
03/08 2016

1.2.2

1.2.2.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

27/07 2016

1.2.1

1.2.1.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

11/07 2016
05/07 2016
01/07 2016

1.0.10

1.0.10.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

01/07 2016

1.0.9

1.0.9.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

30/06 2016

1.0.8

1.0.8.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

30/06 2016

1.0.7

1.0.7.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

30/06 2016

1.0.6

1.0.6.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

29/06 2016

1.0.5

1.0.5.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

14/05 2016

1.0.4

1.0.4.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

03/03 2016

1.0.3

1.0.3.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

14/12 2015

1.0.2

1.0.2.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

09/10 2015

1.0.1

1.0.1.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

31/07 2015

1.0

1.0.0.0

Comments module for Yii2

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2