Using filters on lists
It is often the case that on pages where you list items, you’ll also want some filters in the user interface to help users drill down to a more relevant list. Outlast Framework provides a way to easily generate filters for any of the defined field types.
Generating a filter in the UI
To generate a filter you simply need to invoke the {% inputfilter %}
tag (see docs):
{% inputfilter sample.name %}
Have a look at the docs for defining your own data fields for more details on input filter generation.
Applying filters
To apply filters you simply need to invoke the filter_query()
method on the list:
User::fetch()->filter_query()
See the detailed documentation on this method here.
Custom filtering for models
Sometimes the built-in filtering is not sufficient and you want something specific for a given model object.
In this case you can also define a __onFilterQueryFetcher($this, $query, $similarity_search, $type)
magic method in your model class, which will be called just before the default filtering is applied. You can return an explicit false
to actually prevent the default filtering process to run; in any other case it will run and be applied to the list.
Query format
The format of the GET request is as follows:
filter[fieldName][]=value
…so an example:
filter[name][]=John&filter[featured][]=true
This query is processed by the filter_query()
(see docs).