简体   繁体   中英

How to add multiple levels of sorting in yii2 controller as default sort

i want to sort 3 levels or ads.The first level is premium (status=2) then featured(status=1) and regular(status=0).In the list view i need to show the premium ads first with sort data desc.Means latest post in the premium ads first.Then i want to show the featured ads also like latest post first,Then the regular ads also like latest post first. And i have a default sort like

$dataProvider = $searchModel->search($params);
$defaultSort = $dataProvider->getSort();
$defaultSort->defaultOrder = ['date'=>SORT_DESC];

This code will sort the entire listing with the date sort_desc order.Not filtering premium, featured and regular wise.so i changed this to

$defaultSort->defaultOrder = ['status' => SORT_DESC,'date'=>SORT_DESC];

But nothing happened.How can i do this 3 level sorting in yii2

Should be

$dataProvider = $searchModel->search($params);
$dataProvider->sort->defaultOrder =  ['status' => SORT_DESC,'date'=>SORT_DESC];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM