Cstarrating: Rating For Mutiple Rows

I have a table in the database: products

product | quality

P1 …| 1

P2 …| 5

P3 …| 4

I want to view this table with 10 products and edit the quality of each product with CStarRating.

I think, it’s not possible with the widgets: CGridView or CListView, or?

I could solve this task with a huge amount of programming - but I hope, there is a better solution:

Does Yii provide an easy way for this?

What do you suggest?


"Huge amount of programming" is like 10-20 lines of code.

Basically, you need to attach event handler to ‘change’ event (see api docs for the corresponding js plugin) and call rate action by ajax.

10-20 lines - realy :-o

Without widgets?

I like reading - but I don’t know where to start. I am a little helpless at the moment.

Do you have a small ready example where I can see the necessary things?

Sorry, I haven’t used this component and don’t know what js plugin is used there.

I use Raty. As you can see, some event handlers can be added there. For example, if i have a grid of items, I can add data-score attribute and then use something like



    path: '/js/raty/img', // custom images

    width: 300,

    score: function() {

        return $(this).attr('data-score'); // function to calculate the initial score


    click: function(score, evt) {

        console.log('new score is ' + score); // onclick handler




In your case I suppose you can use something like $(’.star-selector’).on(‘change’, function() {…}).

Anyway, read the docs about js plugin you use, there can be a lot of useful stuff.

Next part is ajax request. You should use POST for it:

$.post('/url/to/ajax/action', {some: 'data'}, function() { console.log('succeed'); }

See JQuery docs for details.

So your client code can look like this (in pseudo-code):

$('.star-rating-selector').on('some-event', function(e) { $.post(...); }<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/wink.gif' class='bbc_emoticon' alt=';)' />;

The action for request processing is old plain action,

public function actionUpdateRating($item_id)


    if (isset($_POST[...])) { ... update value }


just make sure you’re not calling render in it (in order to save traffic).

Ok, that was a lot of pseudo-code :) Concrete implementation will heavily depend on your actual needs, but I think you got the idea.

Thanx for your explanations and tips - but if possible,I will not use other extensions.

Your tips brought me to my final solution:


and combined it with CStarRating.

I think your solution is more sophisticated but too far away from my knowledge at the moment :wink: