To use Elephants Group comment module first you must install module, then you can use comment widget anywhere in your website., (*1)
Installation Steps:
1) run, (*2)
php composer.phar require elephantsgroup/eg-comment "*", (*3)
or add "elephantsgroup/eg-comment": "*"
to the require section of your composer.json file., (*4)
2) migrate database, (*5)
yii migrate --migratiocommentnPath=vendor/elephantsgroup/eg-comment/migrations, (*6)
3) add comment module to common configuration (common/config.php file), (*7)
'modules' => [
...
'comment' => [
'class' => 'elephantsGroup\comment\Module',
],
...
]
, (*8)
4) open access to module in common configuration, (*9)
'as access' => [
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
...
'comment/ajax/*',
...
]
]
, (*10)
5) filter admin controller in frontend configuration (frontend/config.php file), (*11)
'modules' => [
...
'comment' => [
'as frontend' => 'elephantsGroup\comment\filters\FrontendFilter',
],
...
]
, (*12)
5) filter ajax controller in backend configuration (backend/config.php file), (*13)
'modules' => [
...
'comment' => [
'as backend' => 'elephantsGroup\comment\filters\BackendFilter',
],
...
]
, (*14)
Anywhere in your code you can use comment widget as follows:
<?= Comments::widget() ?>
, (*15)
You need to use Comments widget header in your page:
use elephantsGroup\comment\components\Comments;
, (*16)
- item (integer): to separate comments between different items.
<?= Comments::widget(['item' => 1]) ?>
<?= Comments::widget(['item' => $model->id]) ?>
default value for item is 0
- service (integer): to separate comments between various item types.
<?= Comments::widget(['service' => 1, 'item' => $model->id]) ?>
, (*17)
for example you can use different values for different modules in your app, and then use comment widget separately in modules.
default value for service is 0, (*18)
-
enabled_name (boolean): show name in comment form or not, default true
<?= Comments::widget([
'service' => 1,
'item' => $model->id,
'enabled_name' => false,
'view_file' => Yii::getAlias('@frontend') . '/views/comment/widget.php'
]) ?>
, (*19)
-
enabled_subject (boolean): show subject in comment form or not, default true
<?= Comments::widget([
'service' => 1,
'item' => $model->id,
'enabled_name' => false,
'enabled_subject' => true,
'view_file' => Yii::getAlias('@frontend') . '/views/comment/widget.php'
]) ?>
, (*20)
-
enabled_description (boolean): show description in comment form or not, default true
<?= Comments::widget([
'service' => 1,
'item' => $model->id,
'enabled_name' => false,
'enabled_subject' => true,
'enabled_description' => true,
'view_file' => Yii::getAlias('@frontend') . '/views/comment/widget.php'
]) ?>
, (*21)
-
view_file (string): the view file path for rendering, (*22)
<?= Comments::widget([
'service' => 1,
'item' => $model->id,
'color' => 'yellow',
'view_file' => Yii::getAlias('@frontend') . '/views/comment/widget.php'
]) ?>
, (*23)
you can use these variables in your customized view:
* service
* item
* enabled_name
* enabled_subject
* enabled_description, (*24)