I want to set a default configuration for all my GridViews. I did this as following:
我想为我的所有GridView设置默认配置。我这样做如下:
app\config\web.php:
应用程序\ CONFIG \ web.php:
require __DIR__ . '/container.php';
app\config\container.php:
应用程序\ CONFIG \ container.php:
use yii\helpers\Html;
use yii\helpers\Url;
\Yii::$container->set('yii\grid\GridView', [
'layout' => "{items}\n{summary}\n{pager}",
'columns' => [
[
'class' => 'yii\grid\ActionColumn',
'template' => '{edit}{update}',
'buttons' => [
'edit' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', [Url::to(['edit', 'id' => $model->id])]);
},
],
],
],
]);
the part where I define the layout
works fine.
我定义布局的部分工作正常。
But apparently the part with the ActionColumn
doesn't work, because the whole array-index 'columns'
gets overwritten by the column-names when I actually use the GridView in a list.
但显然使用ActionColumn的部分不起作用,因为当我在列表中实际使用GridView时,整个数组索引'列'会被列名覆盖。
How can I set default settings for ActionColumn for all GridViews?
如何为所有GridView设置ActionColumn的默认设置?
1 个解决方案
#1
0
Try setting the default values for ActionColumn separately:
尝试单独设置ActionColumn的默认值:
\Yii::$container->set('yii\grid\ActionColumn', [
'template' => '{edit}{update}',
'buttons' => [
'edit' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', [Url::to(['edit', 'id' => $model->id])]);
},
],
]);
#1
0
Try setting the default values for ActionColumn separately:
尝试单独设置ActionColumn的默认值:
\Yii::$container->set('yii\grid\ActionColumn', [
'template' => '{edit}{update}',
'buttons' => [
'edit' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>', [Url::to(['edit', 'id' => $model->id])]);
},
],
]);