jbellomy / yii2-comments

Yii 2 comments extension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Yii 2 Comments Module

License Latest Stable Version Latest Unstable Version Total Downloads

Code Status

Scrutinizer Code Quality Code Coverage Travis CI Build Status Dependency Status

Installation

Add in composer.json:

{
    "require": {
        "rmrevin/yii2-comments": "1.0.6"
    }
}

In config /protected/config/main.php

<?
return [
	// ...
	'modules' => [
		// ...
		'comments' => 'rmrevin\yii\module\Comments\Module',
	],
	// ...
];

In auth manager add rules:

use \yii\rbac\Role;
use \rmrevin\yii\module\Comments\Permission;
use \rmrevin\yii\module\Comments\rbac\ItsMyComment;

$AuthManager = \Yii::$app->getAuthManager();
$ItsMyCommentRule = new \rmrevin\yii\module\Comments\rbac\ItsMyComment();

$AuthManager->add($ItsMyCommentRule);

$AuthManager->add(new \yii\rbac\Role([
    'name' => Permission::CREATE,
    'description' => 'Can create own comments',
]));
$AuthManager->add(new \yii\rbac\Role([
    'name' => Permission::UPDATE,
    'description' => 'Can update all comments',
]));
$AuthManager->add(new \yii\rbac\Role([
    'name' => Permission::UPDATE_OWN,
    'ruleName' => $ItsMyCommentRule->name,
    'description' => 'Can update own comments',
]));
$AuthManager->add(new \yii\rbac\Role([
    'name' => Permission::DELETE,
    'description' => 'Can delete all comments',
]));
$AuthManager->add(new \yii\rbac\Role([
    'name' => Permission::DELETE_OWN,
    'ruleName' => $ItsMyCommentRule->name,
    'description' => 'Can delete own comments',
]));

Usage

In view

<?
// ...

echo \rmrevin\yii\module\Comments\widgets\CommentListWidget::widget([
    'entity' => (string) 'photo-15', // type and id
]);

About

Yii 2 comments extension

License:MIT License


Languages

Language:PHP 91.4%Language:JavaScript 5.0%Language:CSS 3.7%