I am using CStarRating in my Yii project. What at present I have to do is set rating and then hit submit.This works very well but i want data in db to get update in single Go. I have tried various Ajax based tricks but I am new so I fail.
here is my existing code
$this->widget('CStarRating',array(
'model'=>$model,
'attribute'=>'hotel_rating',
'readOnly'=>FALSE,
));
I have tried following ajax one
$this->widget('CStarRating',array(
'name'=>'rating',
'model'=>$model,
'attribute'=>'hotel_rating',
'callback'=>'
function(){
$.ajax({
type: "GET",
url: "'.Yii::app()->createUrl('hotel/update').'",
data: "id='.$model->id.'&rate=" + $(this).val(),
success: function(msg){
alert("Sucess")
},
error: function(xhr){
alert("failure"+xhr.readyState+this.url)
}
})}'
));
in controller I do but still unlucky
$model->hotel_rating = $_GET['rate']
$model->save()
In controller, I guess it should be
$model->hotel_rating = $_GET['rate'], and similarly $_GET[‘id’] will return the id of the model.