PHPackages                             coderseden/cmt - 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. coderseden/cmt

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

coderseden/cmt
==============

Comments module for Yii2

v2.1.1(5y ago)08MITPHPPHP &gt;=5.6

Since Jul 31Pushed 5y agoCompare

[ Source](https://github.com/coderseden/cmt)[ Packagist](https://packagist.org/packages/coderseden/cmt)[ RSS](/packages/coderseden-cmt/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (2)Dependencies (9)Versions (42)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/7e0fcb4713e702ffa94fc4056794e95e648faf86bc23defeaf328fe40a715a11/68747470733a2f2f706f7365722e707567782e6f72672f636f646572736564656e2f636d742f762f737461626c65)](https://packagist.org/packages/coderseden/cmt)[![Total Downloads](https://camo.githubusercontent.com/33c2aa5aaf195799132116a1e35725046f5b86a563eeb331d9382fb9a22db15f/68747470733a2f2f706f7365722e707567782e6f72672f636f646572736564656e2f636d742f646f776e6c6f616473)](https://packagist.org/packages/coderseden/cmt)[![License](https://camo.githubusercontent.com/4ce66d75238751b66b670a8925f11367325c12198297dac49403f89923f74da6/68747470733a2f2f706f7365722e707567782e6f72672f636f646572736564656e2f636d742f6c6963656e7365)](https://packagist.org/packages/coderseden/cmt)[![Build Status](https://camo.githubusercontent.com/0d873ace8e1249bffa2788d945796b562afa1bdee674f8af4378b6163de714f0/68747470733a2f2f7472617669732d63692e6f72672f636f646572736564656e2f636d742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/coderseden/cmt)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8392670a726b097bf9ae5114dd33dc645f4680740b0f3f45a1579f2e0852536a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f636f646572736564656e2f636d742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/coderseden/cmt/?branch=master)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist coderseden/cmt "*"

```

or add

```
"coderseden/cmt": "*"

```

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/coderseden/cmt/migrations
```

**Module setup**

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

```
'modules' => [
    'comment' => [
        'class' => 'coderseden\cmt\Module',
    ],
]
```

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

```
