Yii2 在 DetailView 中渲染图像 [英] Yii2 Render an image in DetailView
本文介绍了Yii2 在 DetailView 中渲染图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在视图文件中渲染图像.我的代码如下:
= DetailView::widget(['模型' =>$模型,'属性' =>['ID','姓名',//'照片',['属性'='照片','value'=>('<img src =' .'uploads/' . $model->photo . ' height="100" width="100"' .'>')],['属性' =>'生日','格式' =>['日期', 'dd-MM-Y'],],'移动的',],]) ?>
虽然下面的代码有效:
');?>
谢谢.
解决方案
试试这个:
<预><代码>['属性'='照片','值'=>$model->照片,'格式' =>['图像',['width'='100','height'='100']],],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.
解决方案
Try this:
[
'attribute'=>'photo',
'value'=>$model->photo,
'format' => ['image',['width'=>'100','height'=>'100']],
],
这篇关于Yii2 在 DetailView 中渲染图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文