Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How to put an image in GridView in yii2?I have the following code. But its not displaying the image as it is not giving any image url. Where to put the image url?

 <?php echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yiigridSerialColumn'],

        'c_id',
        'name:ntext',
        'description:ntext',
        array(
                'format' => 'image',
               'attribute'=>'logo',

),

        ['class' => 'yiigridActionColumn'],
    ],
]); ?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
616 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try like,

 array(
'format' => 'image',
'value'=>function($data) { return $data->imageurl; },

   ),

And in your model,

public function getImageurl()
{
return Yii::$app->request->BaseUrl.'/<path to image>/'.$this->logo;
}

Don't know this is the right way or not.But this works for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...