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',
]));
In view
<?
// ...
echo \rmrevin\yii\module\Comments\widgets\CommentListWidget::widget([
'entity' => (string) 'photo-15', // type and id
]);