1

I am working on CStar rating widget in yii. I have done as follows:

$review = Reviews::model()->findAll();
        foreach($review as $review)
        {
           $rate=$review['rating'];
           $this->widget('CStarRating',array(
                'name'=>'rating',
                'minRating'=>1,
                'maxRating'=>5,
                'starCount'=>5,
                'value'=>$rate,
                'readOnly'=>true,
            ));
            echo "<br/>";
            echo $review['title'];
            echo "<br/>";
            echo "<font color='brown'>".ucfirst($review['name'])."</font><br/>";
            echo $review['body'];
            echo "<hr/><br/>";
        }
    ?>

When I enter one review in the database, then it is ok but as I add a 2nd review, then both the review stars get mixed.

What should I do in this case?

Asgaroth
  • 4,274
  • 3
  • 20
  • 36
  • have you tried renaming your vars `$reviews = Reviews::model()->findAll(); foreach($reviews as $review)...`? – Stu Jan 16 '13 at 12:35

1 Answers1

1

You are using the 'name' attribute of the widget, so the javascript is getting confused as there will be more than 1 input with the same name, what you have to do is use the 'model' and 'attribute' options for the widget

 $this->widget('CStarRating',array(
                'attribute'=>'rating', //change to the attribute in your model
                'model'=>$review,
                'minRating'=>1,
                'maxRating'=>5,
                'starCount'=>5,
                'value'=>$rate,
                'readOnly'=>true,
            ));

Also you need to rename the variables in your foreach, from:

$review = Reviews::model()->findAll();
foreach($review as $review)

to

$reviews = Reviews::model()->findAll();
foreach($reviews as $review)
Asgaroth
  • 4,274
  • 3
  • 20
  • 36
  • Hey can any one tell me that i am working on the same thing but i am unable to show the stars I am only getting radio buttons? how can I get the stars ? – Rohitashv Singhal Jan 23 '13 at 06:39
  • Thanks guys, I have made the attribute variable as follow `$rate=$review['rating']; $this->widget('CStarRating',array( 'name'=>'rating'.$i, 'minRating'=>1, 'maxRating'=>5, 'starCount'=>5, 'value'=>$rate, 'readOnly'=>true, ));` –  Jan 23 '13 at 06:44