To use Elephants Group star-rating module first you must install module, then you can use star-rating widget anywhere in your website., (*1)
Installation Steps:
1) run, (*2)
php composer.phar require elephantsgroup/eg-star-rating "*", (*3)
or add "elephantsgroup/eg-star-rating": "~1"
to the require section of your composer.json file., (*4)
2) migrate database, (*5)
yii migrate --migrationPath=vendor/elephantsgroup/eg-star-rating/migrations, (*6)
3) add star-rating module to common configuration (common/config.php file), (*7)
'modules' => [
...
'star-rating' => [
'class' => 'elephantsGroup\starRating\Module',
],
...
]
, (*8)
4) open access to module in common configuration, (*9)
'as access' => [
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
...
'star-rating/ajax/*',
...
]
]
, (*10)
5) filter admin controller in frontend configuration (frontend/config.php file), (*11)
'modules' => [
...
'star-rating' => [
'as frontend' => 'elephantsGroup\starRating\filters\FrontendFilter',
],
...
]
, (*12)
5) filter ajax controller in backend configuration (backend/config.php file), (*13)
'modules' => [
...
'star-rating' => [
'as backend' => 'elephantsGroup\starRating\filters\BackendFilter',
],
...
]
, (*14)
Anywhere in your code you can use star-rating widget as follows:
<?= Rate::widget() ?>
, (*15)
You need to use Rate widget header in your page:
use elephantsGroup\starRating\components\Rate;
, (*16)
- 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]) ?>
, (*17)
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]) ?>
, (*18)
-
max_num (integer): maximum possible rate vote
<?= Rate::widget(['service' => 1, ''item' => $model->id, 'min_num' => 1, 'max_num' => 5]) ?>
, (*19)
-
view_file (string): the view file path for rendering, (*20)
<?= Rate::widget([
'service' => 1,
'item' => $model->id,
'color' => 'yellow',
'view_file' => Yii::getAlias('@frontend') . '/views/star-rating/widget.php'
]) ?>
, (*21)
you can use these variables in your customized view:
* service
* item
* min_num
* max_num
* rate_num, (*22)