How do I set a default configuration for GridView in Yii2 without the widget factory?

前端 未结 2 1530
别那么骄傲
别那么骄傲 2021-02-18 23:30

This is what a gridview looks like in Yii2:

 $dataProvider,
    \'filterModel\' => $searchModel,
          


        
2条回答
  •  清酒与你
    2021-02-18 23:50

    You can use Yii::$container->set().

    For example:

    // 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',
        ],
    ]);
    

    For more information: Dependency Injection Container and Practical Usage

    and Yii::$objectConfig has been removed in Yii 2.0.0-beta.

    For example (Since version 2.0.11):

    $config = [
        'id' => 'basic',
        // ...
        'container' => [
            'definitions' => [
                yii\grid\GridView::class => [
                    'tableOptions' => [
                        'class' => 'table table-condensed',
                    ],
                ],
            ],
        ],
    ];
    

    For more information: Application Configurations

提交回复
热议问题