我是一个新的yii2开发人员!我创建了一个GridView,代码如下所示:
<?php Pjax::begin(); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii'grid'ActionColumn'],
['class' => 'yii'grid'CheckboxColumn'],
['class' => 'yii'grid'SerialColumn'],
'id',
'countryCode',
'countryName',
'currencyCode',
],
]); ?>
<?php Pjax::end(); ?>
输出的截图:输出
现在我想有一个列包含一些按钮和按钮,例如打开一个页面或其他东西!我的问题是如何创建这个列
您还可以像这样将按钮(或任意多个)添加到现有的操作列
<?= GridView::widget([
::
::
'columns' => [
[
'class' => 'yii'grid'ActionColumn',
'template' => '{view} {update} {delete} {myButton}', // the default buttons + your custom button
'buttons' => [
'myButton' => function($url, $model, $key) { // render your custom button
return Html::a(..);
}
]
]
::
::
'currencyCode'
]
]); ?>
示例:
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii'grid'ActionColumn'],
['class' => 'yii'grid'CheckboxColumn'],
['class' => 'yii'grid'SerialColumn'],
'id',
'countryCode',
'countryName',
'currencyCode',
[
'label' => 'My Label',
'format' => 'raw',
'value' => Html::a('Click me', ['site/index'], ['class' => 'btn btn-success btn-xs', 'data-pjax' => 0])
]
],
]); ?>
<?php Pjax::end(); ?>
试试:
[
'header' => 'Button',
'content' => function($model) {
return Html::a(..);
}
],
更多信息