Joshi
Joshi

Reputation: 2790

Yii2 Render an image in DetailView

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.

Upvotes: 14

Views: 25958

Answers (6)

Kalpesh
Kalpesh

Reputation: 1

[
    'attribute'=>'profile',
    'value'=>'../uploads/' .$model->profile,
    'format' => ['image',['width'=>'100','height'=>'100']],
],

Upvotes: -1

Prabu Karana
Prabu Karana

Reputation: 302

Try this

[
  'attribute' => 'vUpload',
  'value'=>'uploads/' .$model->vUpload,
  'format' => ['image',['width'=>'100','height'=>'100']],
],

Upvotes: 0

yasir shah
yasir shah

Reputation: 73

Try this:

[
   'attribute'=>'images',
   'value'=> Yii::$app->homeUrl.'uploads/'.$model->images,
   'format' => ['image',['width'=>'100','height'=>'100']],
],

Upvotes: 1

shyam sasi
shyam sasi

Reputation: 97

[
 'attribute'=>'group_pic',
'value'=>('uploads/group_pro_pic/' . $model->group_pic),
'format' => ['image',['width'=>'230','height'=>'200']],
            ]

Upvotes: 2

user2615287
user2615287

Reputation: 91

 DetailView::widget([
        'model' => $model,
        'attributes' => [
            'id',
            'photo:image',
        ],
    ])

Upvotes: 4

Ali MasudianPour
Ali MasudianPour

Reputation: 14459

Try this:

[
    'attribute'=>'photo',
    'value'=>$model->photo,
    'format' => ['image',['width'=>'100','height'=>'100']],
],

Upvotes: 33

Related Questions