Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 Render an image in DetailView

Tags:

yii2

I am trying to render an Image in view file. My code is like below:

<?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'id',
            'name',
            //'photo',
            [
                'attribute'=>'photo',
                'value'=>('<img src =' .'uploads/' . $model->photo . ' height="100" width="100"' .   '>')
            ],


            [
                'attribute' => 'birth_date',
                'format' => ['date', 'dd-MM-Y'],
                        ],  
        'mobile',
            ],

    ]) ?>

Though the code below works:

<?php echo ('<img src =' .'uploads/' . $model->photo .'>'); ?>

Thanks.

like image 220
Joshi Avatar asked Nov 12 '14 21:11

Joshi


2 Answers

Try this:

[
    'attribute'=>'photo',
    'value'=>$model->photo,
    'format' => ['image',['width'=>'100','height'=>'100']],
],
like image 152
Ali MasudianPour Avatar answered Nov 15 '22 16:11

Ali MasudianPour


 DetailView::widget([
        'model' => $model,
        'attributes' => [
            'id',
            'photo:image',
        ],
    ])
like image 4
user2615287 Avatar answered Nov 15 '22 17:11

user2615287