Yii2 Render an image in DetailView

本小妞迷上赌 提交于 2019-12-20 10:39:15

问题


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.


回答1:


Try this:

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



回答2:


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



回答3:


Try this:

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



回答4:


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



回答5:


Try this

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


来源:https://stackoverflow.com/questions/26896529/yii2-render-an-image-in-detailview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!