这是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中,没有widget工厂.相反,看主配置,我期望这将工作:
'grid'=>[ 'class' => 'yii\grid\GridView','tableOptions'=>['class'=>'table table-condensed'],
但是没有.那我做错了什么?任何提示非常感谢.谢谢!
您可以使用Yii :: $container-> set().
原文链接:https://www.f2er.com/php/139562.html例如:
// 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 :: $objectConfig已经在Yii 2.0.0-beta中被删除.
例如(自2.0.11版):
$config = [ 'id' => 'basic',// ... 'container' => [ 'definitions' => [ yii\grid\GridView::class => [ 'tableOptions' => [ 'class' => 'table table-condensed',];
欲了解更多信息:Application Configurations