yiidataGridView::dataProvider 可以接受 yii\data\DataProviderInterface 类型的 类实例; 所以可以使用下面两种(但不限于)方式: 传入 ArrayDataProvider $data = Yii::$app->db->createCommand($sql)->queryAll(); ynew ArrayDataProvider([ "allModels" => $data, ]); 传入 SqlDataProvider new SqlDataProvider([ "sql" => $sql, ]);
yiidataGridView::dataProvider 可以接受
yii\data\DataProviderInterface
类型的 类实例;所以可以使用下面两种(但不限于)方式:
传入 ArrayDataProvider
传入 SqlDataProvider