I got some errors last night doing the example above, I cant remember what hey where though, cause I solved it:p
But thought I could share what I did just in case anyone else googles this:p
Note! I use this in a _view file used by a dataprovider, that is why I use $data->id insteaad of $model->id.
And since the code runs in a lop the id’s had to be diffrent each time.
Now you know that.
What my code does is it sends the vote and id as two get parameters to my rating action in the howto controller,
if the controller returns success it updates a div with "Thank you for voting", then the div fades in slowly,the script pauses for 5 seconds(5000 milliseconds) and then fades out again.
public function actionRating()
{
if ( Yii::app()->request->isAjaxRequest )
{
$model = $this->loadModel( $_GET['id'] );
$model->rating = $_GET['val'];
$model->save();
echo CJSON::encode( array (
'status'=>'success',
'div'=>'Thank you for voting!',
) );
}
}
NOTE! Whats missing is to calculating an average score and present it. I leave that for each person to solve, I haven’t thought about how I want to do it yet so.