GridView多表关联

有些时候,需要多表关联查询,使用SqlDataProvider比较灵活

Controller中

use yii\data\SqlDataProvider;

$dataProvider = new SqlDataProvider([ 
    'sql' =>$sql, 
    'totalCount' => $totalCount, 
    'pagination' => [ 
        'pageSize' => 10, 
    ], 
]); 
$gridcolumn[0]=['class'=>'kartik\grid\SerialColumn'];
$gridcolumn[1]=['label'=>'AA','value'=>"name"];
//省略

View中

<?= GridView::widget([ 
       'dataProvider' => $dataProvider, 
       'columns' =>$gridcolumn,
     ]);
?>

 

你可能感兴趣的:(GridView多表关联)