Answer the question
In order to leave comments, you need to log in
How to set DESC sorting by default for the whole site in yii2?
By default, yii2 receives data from the database in ASC sorting. How to set the default sorting for the entire site, or at least for each model separately?
Answer the question
In order to leave comments, you need to log in
Good afternoon.
Several options for one model.
First
Second when forming $dataProvider
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort' => [
'defaultOrder' => ['id' => SORT_ASC]
]
]);
What for?
Is it hard to do this:
User::find()
->orderBy(['id' => SORT_DESC])
->all();
class UsersRepository
{
public function getLastUsers()
{
return new ActiveDataProvider([
'query' => User::find(),
'sort' => ['defaultOrder' => ['id' => SORT_DESC]]
]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question