Star Rating
You just vote :0
iplayground.com/protected/modules/UiModule/views/ui_other/star_rating.php
echo CHtml::beginForm();
$this->widget('CStarRating',array(
'name'=>'rating',
'minRating'=>1, //minimal value
'maxRating'=>6,//max value
'starCount'=>6, //number of stars
));
echo CHtml::submitButton("Vote!");
echo CHtml::endForm();
echo "You just vote :".$ratingValue;
protected/modules/UiModule/controllers/Ui_otherController.php
public function actionStarRating() {
$ratingValue=0;
if (isset($_GET['rating'])) {
$ratingValue=$_GET['rating']; //according the widget name, in this case is "rating"
}
$this->render('star_rating', array('ratingValue'=>$ratingValue));
}
Star Rating with Ajax
No Result
References
iplayground.com/protected/modules/UiModule/views/ui_other/star_rating.php
//because we are activating CSRF and se using POST, we must give token to the AJAX Parameter
$this->widget('CStarRating',array(
'name'=>'ratingAjax',
'callback'=>'
function(){
$.ajax({
type: "POST",
url: "'.Yii::app()->createUrl('UiModule/ui_other/starRatingAjax').'",
data: "'.Yii::app()->request->csrfTokenName.'='.Yii::app()->request->getCsrfToken().'&rate=" + $(this).val(),
success: function(msg){
$("#result").html(msg);
}})}'
));
echo "<br/>";
echo "<div id='result'>No Result</div>";
protected/modules/UiModule/controllers/Ui_otherController.php
public function actionStarRatingAjax() {
$ratingAjax=isset($_POST['rate']) ? $_POST['rate'] : 0;
echo "You are voting $ratingAjax through AJAX!";
}