在 Yii 中以 1 个视图显示多个 CStarRating
我有一个视图,其中显示了产品的多条评论。每条评论最初都会提交标题、评论内容,并通过 CStarRating 给出评级值。所有这些数据均已成功保存。
在产品视图中,我显示该产品的每条评论(显示相同的信息 - 评论标题、评论内容和评论评级)。
我遇到的问题是,我可以很好地显示评级的数值,但是当我尝试显示通过 CStarRating 为每个评论呈现的值时,只有一个 CStarRating 正确呈现(第一个),所有其他都丢失了它们的值数据。
我的 foreach 循环中的代码是:
<div class="rating">
Rating: <?php echo $review->rating;?>
<?php $this->Widget('CStarRating',array(
'id'=> 'rating'.$review->id,
'name'=>'test'.$review->id,
'attribute'=>'rating',
'value'=> $review->rating,
'readOnly'=>true,
'minRating'=>.5,
'maxRating'=>5,
'starCount'=>5,
'ratingStepSize'=>.5,
));?>
</div>
显示多个评级值的正确语法是什么?
PS 我已经进行了多次搜索,但很惊讶没有找到任何有关显示数据的文档/问题 - 仅插入数据。
I have a view where several reviews are displayed for a product. Each review was initially submitted with a title, review content, and through CStarRating a rating value. All of this data is saved successfully.
In the view for the product I am displaying each review for this product(same information is shown - review title, review content, and review rating).
The problem I am having though is I can display the numerical value of the rating just fine however when I try to display the value rendered through CStarRating for each review only one CStarRating is rendered correctly (the first one) all of the others are missing their data.
The code in my foreach loop is:
<div class="rating">
Rating: <?php echo $review->rating;?>
<?php $this->Widget('CStarRating',array(
'id'=> 'rating'.$review->id,
'name'=>'test'.$review->id,
'attribute'=>'rating',
'value'=> $review->rating,
'readOnly'=>true,
'minRating'=>.5,
'maxRating'=>5,
'starCount'=>5,
'ratingStepSize'=>.5,
));?>
</div>
What is the proper syntax to display the value of multiple ratings?
P.s. I've searched high and low and am surprised to not have found any documentation/questions regarding displaying the data - only inserting the data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有给你一个完整的答案,但我敢打赌这与生成的 JavaScript 有关。检查生成的 HTML/JS。您将在底部找到组件的 JS 代码。看看这是否能为您指明正确的方向。
I do not have a complete answer for you, but I bet this is related to the javascript generated. Check the generated HTML / JS. You'll find the JS code for the components at the bottom. See if that can point you in the right direction.
问题在于评级的数据类型。您必须确保它是整数或浮点(双精度)。这导致了评级小部件以错误格式/错误类型接收数据并且不知道如何呈现它的错误。一旦数据库中的数据类型得到纠正,它就可以很好地工作。
The problem was the data type of the rating. You must make sure it is integer or float(double). That was causing the error that the rating widget was receiving the data in the wrong format/of the wrong type and did not know how to render it. Once the datatype was corrected in the database, it works great.