首页 文章

如何在kartik gridview中创建自定义操作列

提问于
浏览
1

我正在尝试创建一个显示glyphicon的列 . glyphicon将链接到允许用户下载文件的URL . 任何帮助都将受到大力赞赏 . 目前的代码如下:

GridView::widget([
'dataProvider' => $dataProvider,
'pager' => [
    'class' => 'common\widgets\Pagination',
],
'columns' => [
    ['class' => 'yii\grid\SerialColumn'],
    [
        'label' => 'Date',
        'attribute' => 'call_datetime',
        'format' => 'date',
    ],
    [
        'label' => 'Time',
        'attribute' => 'call_datetime',
        'format' => 'time',

    ],
    'call_from',
    'call_to',
    'duration',
    'call_type',
    'extension',

    [
        'label' => 'File',
        'attribute' => 'fname',
        'value' => 'callRecFiles.fname',
    ],

这是用户将要下载的最后一个属性“fname” .

1 回答

  • 1

    fname 字段数组更改为:

    [
        'label' => 'File',
        'attribute' => 'fname',
        'value' => function($model) {
             //here create glyphicon with URL pointing to your action where you can download file, something like 
             return $model->callRecFiles ? Html::a('Download', ['myController/download-action', 'fname' => $model->callRecFiles->fname]) : null;
        }
    ],
    

    并准备适当的操作以允许用户下载文件 .

相关问题