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

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

jcabanillas/yii2-comments
=========================

Comments module for Yii2

01PHP

Since Jun 21Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)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/0b38dcd57a69f2465e1918e9993a2f1e2f161173485e639cadf0735f729ed9e6/68747470733a2f2f706f7365722e707567782e6f72672f6a636162616e696c6c61732f796969322d636f6d6d656e74732f762f737461626c65)](https://packagist.org/packages/jcabanillas/yii2-comments)[![Total Downloads](https://camo.githubusercontent.com/81a82e624742161107926cc91d170952ceb92f51c75395abc601778f5b0943ad/68747470733a2f2f706f7365722e707567782e6f72672f6a636162616e696c6c61732f796969322d636f6d6d656e74732f646f776e6c6f616473)](https://packagist.org/packages/jcabanillas/yii2-comments)[![License](https://camo.githubusercontent.com/fe98dbf5ab20fb074899177cfb56d6333334aa7bf8bbd0967ce7c8085d470023/68747470733a2f2f706f7365722e707567782e6f72672f6a636162616e696c6c61732f796969322d636f6d6d656e74732f6c6963656e7365)](https://packagist.org/packages/jcabanillas/yii2-comments)[![Build Status](https://camo.githubusercontent.com/93096966a7a221719f14be59c6b03c944f5b4cff44c6c1c6c853ff02f894e469/68747470733a2f2f7472617669732d63692e6f72672f6a636162616e696c6c61732f796969322d636f6d6d656e74732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jcabanillas/yii2-comments)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2c05c523ce6fdd43f0411fe783b85caa8c19b8dc9c93ad1edf9fe495366f861e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a636162616e696c6c61732f796969322d636f6d6d656e74732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jcabanillas/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/jcabanillas). 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 jcabanillas/yii2-comments "*"

```

or add

```
"jcabanillas/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/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 `comment` and not otherwise. This is because it is referred [somewhere](https://github.com/jcabanillas/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:**

```
