Yii Framework Forum: Image is not shown in DetailView::widget - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Image is not shown in DetailView::widget What am I doing wrong?

#1 User is offline   mozaika 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 30-October 17

Posted 14 November 2017 - 01:54 PM

Hi there,
why my image is not shown?

<?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'id',
            'name',
            'phone',
            'email:email',
            //'img_name:image',
            [
                'attribute' => 'img_name',
                'format' => 'html',
                'label' => 'Studnt image',
                'value' => function ($model) {
                    return Html::img( $model['img_name'],
                        ['width' => '60px']);
                },
            ],
        ],
    ]) ?>

0

#2 User is offline   umneeq 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 137
  • Joined: 10-October 11
  • Location:Russia

Posted 14 November 2017 - 02:09 PM

Because in $model->img_name not exactly the path.
0

#3 User is offline   alrazi 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,368
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 15 November 2017 - 04:08 AM

make sure your image actually points to a file on the file system. does your img_name column include absolute url with dir or if it is just a filename then you can do something like following.

Html::img("/path/to/upload_dir/" . $model['img_name'], ['width' => '60px']);

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users