这就是Yii2中的gridview:
<?php echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
...
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
我想稍微更改一下我的网格,所以我添加了这一行:
tableOptions'=>['class'=>'table table-condensed'],
这很好用但是......
在Yii 1中,这看起来像这样:
'widgetFactory' => array(
'widgets' => array(
'CGridView' => array(
'htmlOptions' => ['class'=>'table table-condensed']
),
),
),
但是在Yii2中没有小部件工厂。相反,看看主配置,我希望这可以工作:
'grid'=>[
'class' => 'yii\grid\GridView',
'tableOptions'=>['class'=>'table table-condensed'],
],
但事实并非如此。那么我做错了什么?任何提示非常感谢。谢谢!
答案 0 :(得分:18)
您可以使用Yii :: $ container-&gt; set()。
例如:
// add following line in config/web.php and config/console.php
require __DIR__ . '/container.php';
// creates a config/container.php file and add following
\Yii::$container->set('yii\grid\GridView', [
'tableOptions' => [
'class' => 'table table-condensed',
],
]);
有关详情,请访问:Dependency Injection Container和Practical Usage
在Yii 2.0.0-beta中删除了和Yii :: $ objectConfig。
例如(自版本2.0.11起):
$config = [
'id' => 'basic',
// ...
'container' => [
'definitions' => [
yii\grid\GridView::class => [
'tableOptions' => [
'class' => 'table table-condensed',
],
],
],
],
];
有关详细信息:Application Configurations
答案 1 :(得分:4)
Yii::$objectConfig = [
'yii\grid\GridView' => [
'tableOptions'=>['class'=>'table table-condensed']
],
];