PHPackages                             indifferend/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. indifferend/yii2-comments

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

indifferend/yii2-comments
=========================

Comments module for Yii2

2.2.3(4y ago)08MITPHPPHP &gt;=5.6

Since Jun 2Pushed 4y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (9)Versions (7)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/81f6b04989e54be785833f7b7dc68781acbcb8cc0d3bd409b0eef2a8961ff80a/68747470733a2f2f706f7365722e707567782e6f72672f696e646966666572656e642f796969322d636f6d6d656e74732f762f737461626c65)](https://packagist.org/packages/indifferend/yii2-comments)[![Total Downloads](https://camo.githubusercontent.com/c366d733be60adeeadea004c6a41aeb7f97ae750620c73f8b30a6cfadc81ceaa/68747470733a2f2f706f7365722e707567782e6f72672f696e646966666572656e642f796969322d636f6d6d656e74732f646f776e6c6f616473)](https://packagist.org/packages/indifferend/yii2-comments)[![License](https://camo.githubusercontent.com/3b9fef4766e45110fbd51c07199b27c6c49bdb010304b51dc396fce33efbca31/68747470733a2f2f706f7365722e707567782e6f72672f696e646966666572656e642f796969322d636f6d6d656e74732f6c6963656e7365)](https://packagist.org/packages/indifferend/yii2-comments)[![Build Status](https://camo.githubusercontent.com/9a3d1aaac74dc036a49263780ab26299bd789627ae7b5db88dc9a19034f85b96/68747470733a2f2f7472617669732d63692e6f72672f696e646966666572656e642f796969322d636f6d6d656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/indifferend/yii2-comments)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fd8ef04caccfe9c1d716f76424ede712e3a249ca89e32da8bfc988d92b10310b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696e646966666572656e642f796969322d636f6d6d656e74732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/indifferend/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/indifferend). 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 indifferend/yii2-comments "*"

```

or add

```
"indifferend/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/indifferend/yii2-comments/migrations
```

**Module setup**

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

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

> **NOTE:** Module id must be `comment` and not otherwise. This is because it is referred [somewhere](https://github.com/indifferend/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:**

```
