elephantsgroup / eg-star-rating
Yii2 星级评价模块
1.0.1
2018-06-08 19:10 UTC
Requires
This package is not auto-updated.
Last update: 2024-09-16 00:07:28 UTC
README
要使用Elephants Group星级评价模块,首先必须安装模块,然后你可以在网站上的任何位置使用星级评价小部件。
安装步骤
- 运行
php composer.phar require elephantsgroup/eg-star-rating "*"
或者将"elephantsgroup/eg-star-rating": "~1"添加到你的composer.json文件的require部分。
- 迁移数据库
yii migrate --migrationPath=vendor/elephantsgroup/eg-star-rating/migrations
- 将星级评价模块添加到通用配置(common/config.php文件)
...
'star-rating' => [
'class' => 'elephantsGroup\starRating\Module',
],
...
]```
4) open access to module in common configuration
```'as access' => [
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
...
'star-rating/ajax/*',
...
]
]```
5) filter admin controller in frontend configuration (frontend/config.php file)
```'modules' => [
...
'star-rating' => [
'as frontend' => 'elephantsGroup\starRating\filters\FrontendFilter',
],
...
]```
5) filter ajax controller in backend configuration (backend/config.php file)
```'modules' => [
...
'star-rating' => [
'as backend' => 'elephantsGroup\starRating\filters\BackendFilter',
],
...
]```
Using star-rating widget
===
Anywhere in your code you can use star-rating widget as follows:
```<?= Rate::widget() ?>```
You need to use Rate widget header in your page:
```use elephantsGroup\starRating\components\Rate;```
Rate widget parameters
---
- item (integer): to separate Rate between different items.
```<?= Rate::widget(['item' => 1]) ?>```
```<?= Rate::widget(['item' => $model->id]) ?>```
default value for item is 0
- service (integer): to separate star-rating between various item types.
```<?= Rate::widget(['service' => 1, 'item' => $model->id]) ?>```
for example you can use different values for different modules in your app, and then use star-rating widget separately in modules.
default value for service is 0
- min_num (integer): minimum possible rate vote
```<?= Rate::widget(['service' => 1, ''item' => $model->id, 'min_num' => 1]) ?>```
- max_num (integer): maximum possible rate vote
```<?= Rate::widget(['service' => 1, ''item' => $model->id, 'min_num' => 1, 'max_num' => 5]) ?>```
- view_file (string): the view file path for rendering
```<?= Rate::widget([
'service' => 1,
'item' => $model->id,
'color' => 'yellow',
'view_file' => Yii::getAlias('@frontend') . '/views/star-rating/widget.php'
]) ?>```
you can use these variables in your customized view:
* service
* item
* min_num
* max_num
* rate_num