PHPackages                             sjaakp/yii2-comus - 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. sjaakp/yii2-comus

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

sjaakp/yii2-comus
=================

Comment extension for Yii2

1.0.2(6y ago)142MITPHPPHP &gt;=7.0.0

Since Nov 26Pushed 6y ago1 watchersCompare

[ Source](https://github.com/sjaakp/yii2-comus)[ Packagist](https://packagist.org/packages/sjaakp/yii2-comus)[ RSS](/packages/sjaakp-yii2-comus/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

yii2-comus
==========

[](#yii2-comus)

Comment Module for Yii2 PHP Framework
-------------------------------------

[](#comment-module-for-yii2-php-framework)

[![Latest Stable Version](https://camo.githubusercontent.com/7fd9c63e4616cc04fa4ed18a8aa7367fe305af2a5a1ebea705e819f92a2f933f/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d636f6d75732f762f737461626c65)](https://packagist.org/packages/sjaakp/yii2-comus)[![Total Downloads](https://camo.githubusercontent.com/839ce3ff214d905969897e5964531747206939af9ea3fa5da6765da7f4f5ed32/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d636f6d75732f646f776e6c6f616473)](https://packagist.org/packages/sjaakp/yii2-comus)[![License](https://camo.githubusercontent.com/df6a6e27895cf26a5cd92a0f3421ec718af27aaa233b8661feabcecddd51e692/68747470733a2f2f706f7365722e707567782e6f72672f736a61616b702f796969322d636f6d75732f6c6963656e7365)](https://packagist.org/packages/sjaakp/yii2-comus)

**Comus** is a complete comment module for the [Yii 2.0](https://www.yiiframework.com/ "Yii") PHP Framework.

It lets authenticated visitors of a website place comments. The moderator, as well as the administrator of the site can accept or reject comments, either after or before they are submitted. They can also update or delete any comment. Optionally, commenters are allowed to update or delete their own comment.

**Comus** sports three widgets:

- **Comment** Displays a comment block with all the comments issued on a certain model (the *subject*). Intended to be used in a view file.
- **CommentCount** Displays the count of comments issued on a subject. Might be used in an index file.
- **UserComments** Displays links to all comments issued by a certain user, on several subjects.

A demonstration of **Comus** is [here](https://demo.sjaakpriester.nl/comus).

Prerequisites
-------------

[](#prerequisites)

**Comus** relies on [Role-Based Access Control](https://www.yiiframework.com/doc/guide/2.0/en/security-authorization#rbac "Yii2")(RBAC). Therefore, the [`authManager`](https://www.yiiframework.com/doc/api/2.0/yii-base-application#$authManager-detail "Yii2")application component has to be configured. **Comus** works with Yii's `PhpManager` as well as with the `DbManager`.

**Comus** assumes that the site uses [Bootstrap 4](https://www.yiiframework.com/extension/yiisoft/yii2-bootstrap4). I suppose that it will work under Bootstrap 3, but it will be a lot less pleasing to the eye.

**Comus** also assumes that [Font Awesome 5.x](https://fontawesome.com/) is available, either the Free or the Pro version. If you're adventurous, you may adapt the [`icons` option](#module-options)of the module to make **Comus** work with another icon font.

It is strongly advised that the app uses [Pretty URLs](https://www.yiiframework.com/doc/guide/2.0/en/runtime-routing#using-pretty-urls).

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

[](#installation)

Install **yii2-comus** in the usual way with [Composer](https://getcomposer.org/). Add the following to the require section of your `composer.json` file:

`"sjaakp/yii2-comus": "*"`

or run:

`composer require sjaakp/yii2-comus`

You can manually install **yii2-comus** by [downloading the source in ZIP-format](https://github.com/sjaakp/yii2-comus/archive/master.zip).

#### Module

[](#module)

**Comus** is a [module](https://www.yiiframework.com/doc/guide/2.0/en/structure-modules#using-modules "Yii2")in the Yii2 framework. It has to be configured in the main configuration file, usually called `web.php` or `main.php` in the `config`directory. Add the following to the configuration array:

```

   // ... more information about $model ...

```

Likewise in the `view` file for the Movie model.

In the `index` files we might use the **CommentCount** widget:

```

```

The site may also provide in displaying information about registered users. The `view` file for the User model can use the **UserComments** widget and may look like this:

```

   // ... more information about $user ...

```

#### Comment levels

[](#comment-levels)

A comment directly on a subject is said to be of *level 0*. A comment on such comment is said to be a *reply* or a comment of *level 1*. And so on. The maximum level of a comment is settable in the module configuration. Default is 0, meaning that only direct comments are possible. Don't set the maximum level to high, if only because each level indents somewhat.

Notice that if the moderator deletes a comment, all of its replies are deleted as well.

##### Comment block as seen by guest user

[](#comment-block-as-seen-by-guest-user)

[![Comment Block](img/block-guest.gif?raw=true "Comus' comment block as seen by guest")](img/block-guest.gif?raw=true)

Comments by moderators are distinguished by a light background color. Guest is not able to issue a comment, she should login first.

##### Comment block as seen by authenticated user

[](#comment-block-as-seen-by-authenticated-user)

[![Comment Block](img/block-user.gif?raw=true "Comus' comment block as seen by authenticated user")](img/block-user.gif?raw=true)

His own comments have a light cyan background color. Hovering over a comment shows a button to issue a reply on it (if maxLevel &gt; 0).

##### Comment block as seen by moderator

[](#comment-block-as-seen-by-moderator)

[![Comment Block](img/block-moderator.gif?raw=true "Comus' comment block as seen by moderator")](img/block-moderator.gif?raw=true)

Content of rejected comments is readable. Hovering over a comment shows several buttons to manage it.

##### Buttons

[](#buttons)

[![Buttons](img/buttons.gif?raw=true "Comus' buttons")](img/buttons.gif?raw=true)

From left to right:

- **accept/reject** comment
- **previous/next** pending comment
- **update** comment
- **delete** comment
- **reply** to comment

Which buttons appear on hovering above a comment, depends on the permissions of the user, and on the status of the comment.

Permissions
-----------

[](#permissions)

**Comus** defines a few [Permissions](https://www.yiiframework.com/doc/guide/2.0/en/security-authorization#rbac). They are:

NameDescription**createComment**Issue a comment**updateComment**Update a comment**deleteComment**Delete a comment**updateOwnComment**Update self-created comment**deleteOwnComment**Delete self-created comment**manageComments**Accept or reject commentsOne Role is defined: **moderator**. Associated Permissions are **updateComment**, **deleteComment**, and **manageComments**.

If the site sports a Role **admin**, the Role **moderator** is included.

Only moderators are allowed to view the comments overview, on URL:

```
example.com/comment

```

From there, they can easily jump to pending records, waiting to be accepted or rejected.

**Notice** that in the default configuration, **Comus** allows *all* authenticated users to create comments, and it's not necessary to explicitly give them permission. The **createComment**Permission is for scenarios where you want to restrict the allowance to issue comments.

Module options
--------------

[](#module-options)

The **Comus** module has a range of options. They are set in the application configuration like so:

```
