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.

Hope you find these tidbits of information useful.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s