php - yii2 中 gridview 中的图像

标签 php gridview yii2

如何在yii2的GridView中放一张图片?我有下面的代码。但它没有显示图像,因为它没有提供任何图像 url。图片 url 放在哪里?

 <?php echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],

        'c_id',
        'name:ntext',
        'description:ntext',
        array(
                'format' => 'image',
               'attribute'=>'logo',

),

        ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>

最佳答案

试试看,

 array(
'format' => 'image',
'value'=>function($data) { return $data->imageurl; },

   ),

在你的模型中,

public function getImageurl()
{
return \Yii::$app->request->BaseUrl.'/<path to image>/'.$this->logo;
}

不知道这是不是正确的方法。但这对我有用。

关于php - yii2 中 gridview 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21880511/

相关文章:

php - mysql-查询其他表条件PHP

Python 结构的 PHP 替代品

c# - 如何在c#中设置gridview列项样式

jquery - 使用 jQuery 的 GridView 向上和向下导航

mysql - Yii2、ActiveQuery、subQuery 没有带 ID 的条目

php - 新的 Laravel 安装 v 5.4 index.php 抛出解析错误。 PHP 7.2.10-0ubuntu0.18.04.1

javascript - PHP 和 Ajax 在回调和返回数组中使用 foreach 循环

c# - 如何通过 c# 从 asp.net 中的 excel 文件加载 gridview?

php - yii2 - 如何使用条件逻辑使复选框可见

php - 在 Yii 2 的内联验证器中验证多个属性