Use YII's generic, paginated queries for RESTful services

With YII2 it is easy to create views in which the user can search data, which is translated in paginated queries.

I would like to use these queries as well for my RESTful services, but can’t find how to do this. Only ‘sort’ seems to work, but it looks like the sort is being done after the query.

Do I have to write my own queries to the Controller or is there a way to use the generic ones already available in YII2?


Simply return a DataProvider from your REST controller’s action, and Yii will automatically handle the pagination for you.