[
'label' => 'stars',
'value' => function($model){
$stars = $model->score;
$result = "";
for($i=1; $i<=$stars;$i++){
$result .= "<span class='star'>☆</span>";
}
return $result;
},
],
鉴于上述情况,我只需要显示星星,但我会在生成的网格中显示出来:
<span class='star'>☆</span> <span class='star'>☆</span> <span class='star'>☆</span>
但我想要3个风格的明星。 任何帮助将不胜感激!
答案 0 :(得分:1)
在 GridView 列选项中将format
设置为 html ,如下所示
[
'label' => 'stars',
'value' => function($model){
$stars = $model->score;
$result = "";
for($i=1; $i<=$stars;$i++){
$result .= "<span class='star'>☆</span>";
}
return $result;
},
'format' => 'html'
],
答案 1 :(得分:1)
[
'label' => 'stars',
'format'=>'html', // Use this Line
'value' => function($model){
$stars = $model->score;
$result = "";
for($i=1; $i<=$stars;$i++){
$result .= '<i class="fa fa-star-half-o" aria-hidden="true"></i>';
}
return $result;
},
],