2017-10-08 5 views
0
[ 
    'label' => 'stars', 
    'value' => function($model){ 

    $stars = $model->score; 
    $result = ""; 
    for($i=1; $i<=$stars;$i++){ 
     $result .= "<span class='star'>☆</span>"; 
    } 
    return $result; 
    }, 
], 

Compte tenu de ce qui précède, je dois montrer les étoiles seulement, mais je reçois ci-dessous dans la grille produit:fonction en sortie activeDataProvider retour HTML dans yii2

<span class='star'>☆</span> <span class='star'>☆</span> <span class='star'>☆</span> 

Mais je veux 3 étoiles de style. Toute aide serait grandement appréciée!

Répondre

1

Set format comme html dans GridView l'option Colonnes comme ci-dessous

[ 
    'label' => 'stars', 
    'value' => function($model){ 
     $stars = $model->score; 
     $result = ""; 
     for($i=1; $i<=$stars;$i++){ 
      $result .= "<span class='star'>☆</span>"; 
     } 
     return $result; 
    }, 
    'format' => 'html' 
], 

Se référer Yii2 Grid Data Columns Format

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