In order to customize the request you can define multiple filter options:
Set a sort order for a given field.
setSort(['id' => SORT_ASC]);
or the opposite way
setSort(['id' => SORT_DESC]);
- SORT_ASC = 1,2,3
- SORT_DESC = 3,2,1
The filters must be enabled on the api side, otherwise it wont have any effect.
Example usage assuming filters are configured on api:
setFilter(['lang_id' => 1]); // like a where condition lang_id=1
greather then, smaller then operators:
setFilter(['publication_date' => ['lt' => strtotime('tomorrow'), 'gt' => strtotime('yesterday')]); //like >= and <= conditions for two fields.
Example using the in condition for both languages:
setFilter([
'lang_id' => ['in' => [1,2]]
]);
All posible operators:
- and (AND)
- or (OR)
- not (NOT)
- lt (<)
- gt (>)
- lte (<=)
- gte (>=)
- eq (=)
- neq (!=)
- in (IN)
- nin (NOT IN)
- like (LIKE)
combine two conditions with which are AND conditions:
setFilter([
'publication_date' => ['lt' => strtotime('tomorrow'), 'gt' => strtotime('yesterday')],
'lang_id' => 2
]);
Two conditions but connected as OR condition:
setFilter([
'or' => [
['lang_id' => 1],
['publication_date' => ['gt' => time()]],
]
])
@see https://www.yiiframework.com/doc/api/2.0/yii-data-datafilter