有些时候,需要多表关联查询,使用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中
$dataProvider, 'columns' =>$gridcolumn, ]); ?>