saegeek
(Abdallah)
1
Hi to all,
I’m trying to display CStarRating from the DB records i just saved with a read-write CStarRating.
I get the correct number in this ‘itemView’ :
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('rating')); ?>:</b>
<?php echo CHtml::encode($data->rating); ?>
<br />
</div>
But when i replace echo CHtml::encode($data->rating) by:
<?php $this->widget('CStarRating',array(
'model'=>$data,
'attribute'=>'rating',
'maxRating'=>5,
'readOnly'=>true
)); ?>
I get:
saegeek
(Abdallah)
2
because $data was not a model instance (in CListview) i used this instead :
<?php $this->widget('CStarRating',array(
'attribute'=>'rating',
'name'=>'rating',
'value'=>$data->rating,
'maxRating'=>5,
'readOnly'=>true,
)); ?>
but same result
saegeek
(Abdallah)
3
oooooooh yeah !
It worked with this code :
<?php $this->widget('CStarRating',array(
'attribute'=>'rating',
'name'=>'rating_'.$data->id,
'value'=>$data->rating,
'id'=>'rating_'.$data->id,
'maxRating'=>5,
'readOnly'=>true,
)); ?>
saegeek
(Abdallah)
4
And i had to add an "id" property into my CListView to avoid the loss of CSS styles (stars) at pagination (page change):
<?php
$this->widget('zii.widgets.CListView',array(
'id' => '#foo',
'dataProvider'=>$dataProvider,
...
Narretz
(Mjstaffa)
5
Thanks for updating the posts! It’s always helpful for others, when they find it via google etc.
Thank you so much Saegeek!! I couldn’t find an example of how to achieve this until I came across your post. Wish I could buy you lunch