本文介紹了yii2 中 gridview 中的圖像的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
如何在yii2的GridView中放置圖片?我有以下代碼.但它不顯示圖像,因為它沒有提供任何圖像 url.圖片網址放在哪里?
How to put an image in GridView in yii2?I have the following code. But its not displaying the image as it is not giving any image url. Where to put the image url?
<?php echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yiigridSerialColumn'],
'c_id',
'name:ntext',
'description:ntext',
array(
'format' => 'image',
'attribute'=>'logo',
),
['class' => 'yiigridActionColumn'],
],
]); ?>
推薦答案
試試看,
array(
'format' => 'image',
'value'=>function($data) { return $data->imageurl; },
),
在你的模型中,
public function getImageurl()
{
return Yii::$app->request->BaseUrl.'/<path to image>/'.$this->logo;
}
不知道這是否正確.但這對我有用.
Don't know this is the right way or not.But this works for me.
這篇關于yii2 中 gridview 中的圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!