Model::find() default order

Hi everybody.

I have this code i use to populate a select.




$peopleList = \yii\helpers\ArrayHelper::map(app\models\People::find()->all(),'id','Name');



What if i wanted to sort and filter that using the PeopleSearch->search() function (like the default index action generated by Gii does)?

I would like to define a default order by and a default filter used by gridviews and the select inputs.

Default order is set in ActiveDataProvider definition:




 $dataProvider = new ActiveDataProvider([

     'query' => $query,

     'sort'=> ['defaultOrder' => ['topic_order'=>SORT_ASC]]

 ]);



Default sort is set in $query object.

I know, i used that code before, but i want to have a default order used by all find functions / activedataprovider objects for that object. If the search function of the searchmodel can’t be called by the base model i’ll define a custom function inside the model and use it whenever i have to get a list of that objects.

Overwrite "find" then?

http://www.yiiframework.com/doc-2.0/yii-db-activerecordinterface.html#find()-detail