kl83 / yii2-rating-widget
允许您为某个东西设置星级评价或显示它。
v2.0.1
2018-09-09 09:38 UTC
Requires
- php: >=5.4.0
- npm-asset/font-awesome: ^4.0
- yiisoft/yii2: ^2.0.0
README
允许您为某个东西设置星级评价或显示它。
安装
安装此扩展的首选方式是通过composer。
运行以下命令之一
php composer.phar require kl83/yii2-rating-widget ^2.0
或
"kl83/yii2-rating-widget": "^2.0"
将以下内容添加到您的composer.json文件的要求部分。
使用方法
使用FontAwesome资产来显示星级。当前使用版本为4.7。如果您在项目中没有它,必须注册\kl83\widgets\RatingWidgetFaAsset资产。
\kl83\widgets\RatingWidgetFaAsset::register(\Yii::$app->view);
输入小部件
$form->field($model, 'rating')->widget('kl83\widgets\RatingInput', [ 'containerOptions' => ['class' => 'some-class'], // HTML attributes 'maxRating' => 10, // stars count, default - 5 ]);
// Sets 5 stars rating jQuery('.widget').ratingInput('set', 5);
显示小部件
\kl83\widgets\RatingWidget::widget([ 'maxRating' => 10, // stars count, default - 5 'options' => ['class' => 'some-class'], // HTML attributes 'value' => 4.5, // highlighted stars count ]);
// Initialize widget jQuery('.widget').ratingWidget(); // Sets 5 stars rating jQuery('.widget').ratingWidget('set', 5);
许可证
MIT许可证