This module provide a comments managing system for Yii2 application.
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yii2mod/yii2-comments "*"
or add
"yii2mod/yii2-comments": "*"
to the require section of your composer.json.
1. Manage comments in admin panel:
1.1 Add the following code to admin module section in main config
'controllerMap' => [
'comments' => 'yii2mod\comments\controllers\ManageController'
]
1.2 Run migrations:
php yii migrate --migrationPath=@vendor/yii2mod/yii2-comments/migrations
You can then access to management section through the following URL:
http://localhost/path/to/index.php?r=admin/comments/index
2. Usage comment widget in view:
2.1 Add module to config section:
'modules' => [
'comment' => [
'class' => 'yii2mod\comments\Module'
]
]
2.2 Use in view:
<?php echo \yii2mod\comments\widgets\Comment::widget([
'model' => $model,
'relatedTo' => 'User ' . \Yii::$app->user->identity->username . ' commented on the page ' . \yii\helpers\Url::current() // for example
]); ?>
2.3 You can use your own template for render comments.
<?php echo \yii2mod\comments\widgets\Comment::widget([
'model' => $model,
'commentView' => '@app/views/site/comments/index' //path to your template
]); ?>
2.4 Use the following code for multiple widgets on the same page:
echo \yii2mod\comments\widgets\Comment::widget([
'model' => $model,
]);
echo \yii2mod\comments\widgets\Comment::widget([
'model' => $model2,
'formId' => 'comment-form2'
]);