More information about this topic
Reset database
 | 
Star Rating
You just vote :0

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($_POST['rating'])) {
			$ratingValue=$_POST['rating']; //according the widget name, in this case is "rating"
		}
		$this->render('star_rating', array('ratingValue'=>$ratingValue));
	}
Star Rating with Ajax

No Result
References

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!";
	}
Fork me on GitHub