elephantsgroup/eg-comment

Yii2评论模块

安装: 39

依赖: 4

建议: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 7

类型:yii2-extension

1.0.2 2019-01-13 11:42 UTC

This package is not auto-updated.

Last update: 2024-09-17 11:40:17 UTC


README

要使用Elephants Group评论模块,首先您必须安装模块,然后您可以在网站的任何地方使用评论小部件。

安装步骤

  1. 运行

php composer.phar require elephantsgroup/eg-comment "*"

或将"elephantsgroup/eg-comment": "*"添加到您的composer.json文件的require部分。

  1. 迁移数据库

yii migrate --migratiocommentnPath=vendor/elephantsgroup/eg-comment/migrations

  1. 将评论模块添加到通用配置(common/config.php文件)
    ...
    'comment' => [
        'class' => 'elephantsGroup\comment\Module',
    ],
    ...
]```

4) open access to module in common configuration

```'as access' => [
    'class' => 'mdm\admin\components\AccessControl',
    'allowActions' => [
        ...
        'comment/ajax/*',
        ...
    ]
]```

5) filter admin controller in frontend configuration (frontend/config.php file)

```'modules' => [
    ...
    'comment' => [
        'as frontend' => 'elephantsGroup\comment\filters\FrontendFilter',
    ],
    ...
]```

5) filter ajax controller in backend configuration (backend/config.php file)

```'modules' => [
    ...
    'comment' => [
        'as backend' => 'elephantsGroup\comment\filters\BackendFilter',
    ],
    ...
]```

Using comment widget
===

Anywhere in your code you can use comment widget as follows:
```<?= Comments::widget() ?>```

You need to use Comments widget header in your page:
```use elephantsGroup\comment\components\Comments;```

Comment widget parameters
---

- 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]) ?>```

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

- 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'
]) ?>```

- 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'
]) ?>```

- 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'
]) ?>```

- view_file (string): the view file path for rendering

```<?= Comments::widget([
    'service' => 1,
    'item' => $model->id,
    'color' => 'yellow',
    'view_file' => Yii::getAlias('@frontend') . '/views/comment/widget.php'
]) ?>```

you can use these variables in your customized view:
* service
* item
* enabled_name
* enabled_subject
* enabled_description