yii 图片展示

<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'name',
'time',
'pic',
],
]) ?>

是首页展示的几个测试字段 , pic 是本地数据库图片的路径 , 这时候首页显示的是

要显示图片就把'pic'换成

[
    'attribute'=>'pic',
    'format' => 'raw',
    'value' => function($model){
        return Html::img($model->pic);
    }

],如果你的图片地址没有问题就可以显示了


原文地址:https://www.cnblogs.com/myyuanyuan/p/6238734.html