Yii2在DetailView中渲染图像

时间:2014-11-12 21:04:04

标签: yii2

我正在尝试在视图文件中呈现图像。我的代码如下:

<?= 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',
            ],

    ]) ?>

虽然以下代码有效:

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

感谢。

6 个答案:

答案 0 :(得分:27)

试试这个:

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

答案 1 :(得分:3)

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

答案 2 :(得分:1)

试试这个:

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

答案 3 :(得分:0)

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

答案 4 :(得分:0)

尝试一下

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

答案 5 :(得分:-1)

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