Hi, I’m using the CStarRating class but I can’t show in alert() the data I pass by echo() via an action.
Here the code of the widget:
$this->widget('CStarRating', array(
'model' => Offers::model(),
'attribute' => 'rating',
'readOnly' => false,
'htmlOptions' => array('id'=>'offer_'.$data->id),
'maxRating' => 5,
'callback' => '
function() {
$.post(
"'.Yii::app()->createUrl('offers/index').'",
"action=rate&stars="+$(this).val()+"&offerID='.$data->id.'",
function(msg) { alert(msg); }
);
}
',
));
and here the code of the action:
if(isset($_POST['action'])) {
if($_POST['action'] == 'rate') {
$stars = filter_input(INPUT_POST, 'stars', FILTER_SANITIZE_NUMBER_INT);
$offerID = filter_input(INPUT_POST, 'offerID', FILTER_SANITIZE_NUMBER_INT);
$offer = Offers::model()->findByPk($offerID);
$rating = $offer->rating;
$reviews = $offer->reviews;
$offer->rating = round(($rating * $reviews + $stars) / ($reviews + 1));
$offer->reviews = $reviews + 1;
$offer->save();
echo $offer->rating;
}
}
Instead of showing $offer->rating the alert shows the whole page source code.
What’s the problem? Thank you for your support.