2017-08-03 97 views
0

我正在尝试创建一个显示图形的列。图形将链接到允许用户下载文件的URL。任何帮助将大规模赞赏。当前代码如下:如何在kartik gridview中创建自定义动作列

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'。

回答

0

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; 
    } 
], 

并准备采取适当的行动,以允许用户下载文件。

+0

再次感谢你@Yupik。然而,直到我加入 ''format'=>'raw'' 链接显示为纯文本 – Kyle