PHPackages                             dgoriaev/yii2-comments - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dgoriaev/yii2-comments

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

dgoriaev/yii2-comments
======================

Comments module for Yii2

1.0.0(1y ago)12MITPHPPHP &gt;=8.0

Since Oct 3Pushed 1y agoCompare

[ Source](https://github.com/DplusG/yii2-comments)[ Packagist](https://packagist.org/packages/dgoriaev/yii2-comments)[ RSS](/packages/dgoriaev-yii2-comments/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (9)Versions (2)Used By (0)

 [ ![](https://avatars0.githubusercontent.com/u/993323) ](https://github.com/yiisoft)

Yii2 Comments Extension
=======================

[](#yii2-comments-extension)

This module provides a comments managing system.

[![Latest Stable Version](https://camo.githubusercontent.com/bb57ac34c8bfff46452d2cd9d2ecfa8dfdd9b9a1e839bbc78b146683837a5af7/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d636f6d6d656e74732f762f737461626c65)](https://packagist.org/packages/yii2mod/yii2-comments)[![Total Downloads](https://camo.githubusercontent.com/f4bd000e2bc113611644994b2cc42ae7253d6d2f8645a8bfd28518aee1cff114/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d636f6d6d656e74732f646f776e6c6f616473)](https://packagist.org/packages/yii2mod/yii2-comments)[![License](https://camo.githubusercontent.com/2732f3cf0c42e37325a51c346a6a0aed73885117022eb09bf3d8dc5d762811dd/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d636f6d6d656e74732f6c6963656e7365)](https://packagist.org/packages/yii2mod/yii2-comments)[![Build Status](https://camo.githubusercontent.com/ff593286519b01354171e43f4213df599845ec9bbc74d40f0080e8357f90032f/68747470733a2f2f7472617669732d63692e6f72672f796969326d6f642f796969322d636f6d6d656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yii2mod/yii2-comments)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/313483c70823b5303afadd37d778486164dd38a8c25014bcae285edeb46e26c1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796969326d6f642f796969322d636f6d6d656e74732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yii2mod/yii2-comments/?branch=master)

Support us
----------

[](#support-us)

Does your business depend on our contributions? Reach out and support us on [Patreon](https://www.patreon.com/yii2mod). All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

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
-------------

[](#configuration)

**Database Migrations**

Before using Comments Widget, we'll also need to prepare the database.

```
php yii migrate --migrationPath=@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](https://github.com/yii2mod/yii2-comments/blob/master/traits/ModuleTrait.php#L20) 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:

> 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.

> 2. When you delete a comment, all nested comments will be marked as `deleted`.

> 3. You can override default CommentModel class by changing the property `commentModelClass` in the Comment Module.

> 4. 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
-----

[](#usage)

**Basic example:**

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

```

**You can use your own template for render comments:**

```

```

**Use the following code for multiple widgets on the same page:**

```
