参考链接:https://blog.csdn.net/weixin_30686845/article/details/95888286
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel frontend\models\FileSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Files';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="file-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<!--?= Html::a('Create File', ['create'], ['class' => 'btn btn-success']) ?-->
</p>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// 'id',
'filename',
'filepath',
// 'create_at',
'update_at',
// ['class' => 'yii\grid\ActionColumn'],//自定义控制器按钮
['class' => 'yii\grid\ActionColumn','template' => '{view}{mydef}',
'buttons'=>[
'mydef' => function ($url, $model, $key) {
$url="index.php?r=file/readfile&id=".$model->id;
$options = [
'title' => Yii::t('yii', 'View'),
'aria-label' => Yii::t('yii', 'View'),
'data-pjax' => '0',
];
return Html::a('<span class="glyphicon glyphicon-compressed"></span>', $url, $options);
}
]
],
],
]); ?>
</div>