Why ActiveController can't filter records?


(xNicox) #1

Hi, i’m quite new to REST, I wondering why REST in YII 2, can’t filter records, like other Controllers ?
I have to search Google and follow this instructions to filter records

I guess that making a GET to a table in real world should expect a bunch of data, it is clear that you need to filter data before returning…

Best Regards.


(Basil) #2

You can filter models by adding a filter model and pass the get param (or body param) filter to the rest route: https://www.yiiframework.com/doc/guide/2.0/en/rest-resources#filtering-collections

I must admit, at first sight it looks way to complex but once understand you will be able to filter for any condition while requesting the data (https://www.yiiframework.com/doc/guide/2.0/en/output-data-providers#filtering-data-providers-using-data-filters).

may this helps, i was not sure if i understood your question correctly :slight_smile: