activeDataProvider 输出中的函数在 yii2 中返回 HTML

function in activeDataProvider output returning HTML in yii2

[
  '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 个造型星星。 任何帮助将不胜感激!

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'
],

参考Yii2 Grid Data Columns Format

         [
            '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;
            },
        ],