composer require "rmrevin/yii2-comments:1.2.*"
In config /protected/config/main.php
<?php
return [
// ...
'modules' => [
// ...
'comments' => [
'class' => 'rmrevin\yii\module\Comments\Module',
'userIdentityClass' => 'app\models\User',
'useRbac' => true,
]
],
// ...
];
In auth manager add rules (if Module::$useRbac = true
):
<?php
use \rmrevin\yii\module\Comments\Permission;
use \rmrevin\yii\module\Comments\rbac\ItsMyComment;
$AuthManager = \Yii::$app->getAuthManager();
$ItsMyCommentRule = new ItsMyComment();
$AuthManager->add($ItsMyCommentRule);
$AuthManager->add(new \yii\rbac\Permission([
'name' => Permission::CREATE,
'description' => 'Can create own comments',
]));
$AuthManager->add(new \yii\rbac\Permission([
'name' => Permission::UPDATE,
'description' => 'Can update all comments',
]));
$AuthManager->add(new \yii\rbac\Permission([
'name' => Permission::UPDATE_OWN,
'ruleName' => $ItsMyCommentRule->name,
'description' => 'Can update own comments',
]));
$AuthManager->add(new \yii\rbac\Permission([
'name' => Permission::DELETE,
'description' => 'Can delete all comments',
]));
$AuthManager->add(new \yii\rbac\Permission([
'name' => Permission::DELETE_OWN,
'ruleName' => $ItsMyCommentRule->name,
'description' => 'Can delete own comments',
]));
After you downloaded and configured rmrevin/yii2-comments
,
the last thing you need to do is updating your database schema by applying the migrations:
In command line
:
php yii migrate/up --migrationPath=@vendor/rmrevin/yii2-comments/migrations/
In view
<?php
// ...
use rmrevin\yii\module\Comments;
echo Comments\widgets\CommentListWidget::widget([
'entity' => (string) 'photo-15', // type and id
]);