Saturday, June 11, 2016

Yii2 Show image at a GridView

[
                'attribute' => 'itm_image',
                'format' => 'image',
                'value' => function($data) {
                    if($data->itm_image){
                        return \Yii::getAlias('@web/uploads/products/').$data->itm_image;
                    }
                    else{
                        return \Yii::getAlias('@web/uploads/products/no.png');
                    }
                },
                'contentOptions' => ['class' => 'item_image_grid img-responsive img-rounded']
            ],
            [
                'attribute' => 'itm_image',
                'format' => 'html',
                'value' => function ($data) {
                    if($data->itm_image) {
                        return Html::img('@web/uploads/products/' . $data->itm_image,
                            ['width' => '60px', 'class' => 'img-responsive img-rounded']);
                    }
                    else{
                        return Html::img('@web/uploads/products/no.png',
                            ['width' => '60px', 'class' => 'img-responsive img-rounded']);
                    }
                },
            ],

No comments:

Post a Comment