In Yii2 we can use Sort class for sort the data and also define multiple columns for sorting.
Yii provides multiple types of sorting like asc, desc and user can also set default sort for all attributes.
Sorting in Yii2
use yii\data\Sort;
$sorting = new Sort([
'attributes' => [
'name' => [
'asc' => ['name' => SORT_ASC, 'id' => SORT_ASC],
'desc' => ['username' => SORT_DESC],
'default' => SORT_DESC,
],
],
]);
$user= User::find()
->where(['is_visible' => 1])
->orderBy($sorting->orders)
->all();