if(!\Yii::$app->request->get('sort')) {
\Yii::$app->request->set('sort')...
}
if(!\Yii::$app->request->get('sort')) {
Yii::$app->request->setQueryParams(['sort' => 'name']);
}
if(!\Yii::$app->request->get('sort')) {
$this->redirect(['view', 'sort' => 'name']);
}
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => [
'name' => SORT_ASC
]
],
]);