Yii2 ActiveDataProvider query options

Yii2 ActiveDataProvider query options

The Yii2 documentation is terrible. Many options are mentioned in an offhand kind of way in the middle of paragraphs and under unclear examples. If you are using ActiveDataProvider to return data to your endpoint, here are some options that you may have missed.

  1. http://foo.com/bar?expand=baz,foo The expand option will return the data on related models which where defined in that models extraFields array.
  2. http://foo.com/bar?sort=baz,-foo The sort option orders your resultset by the fields specified. Put a ‘-‘ to sort descending.
  3. http://foo.com/bar?page=3&page-size=10 The page-size option isn’t clear in the docs. It will alter the number of records per page so that you can customize the response’s per-page pagination, useful when giving the user the option of multiple number of records per page.