Fixes #2022: Added info about yii\db\Query::andFilterCompare() to guide

This commit is contained in:
Alexander Makarov
2016-05-01 00:51:19 +03:00
parent 63cac32fbc
commit 9e7d5041cc
2 changed files with 17 additions and 1 deletions

View File

@ -351,6 +351,20 @@ Like [[yii\db\Query::andWhere()|andWhere()]] and [[yii\db\Query::orWhere()|orWhe
[[yii\db\Query::andFilterWhere()|andFilterWhere()]] and [[yii\db\Query::orFilterWhere()|orFilterWhere()]] [[yii\db\Query::andFilterWhere()|andFilterWhere()]] and [[yii\db\Query::orFilterWhere()|orFilterWhere()]]
to append additional filter conditions to the existing one. to append additional filter conditions to the existing one.
Additionally, there is [[yii\db\Query::andFilterCompare()]] that can intelligently determine operator based on what's
in the value:
```php
$query->andFilterCompare('name', 'John Doe');
$query->andFilterCompare('rating', '>9');
$query->andFilterCompare('value', '<=100');
```
You can also specify operator explicitly:
```php
$query->andFilterCompare('name', 'Doe', 'like');
```
### [[yii\db\Query::orderBy()|orderBy()]] <span id="order-by"></span> ### [[yii\db\Query::orderBy()|orderBy()]] <span id="order-by"></span>

View File

@ -395,9 +395,11 @@ class PostSearch extends Post
return $dataProvider; return $dataProvider;
} }
} }
``` ```
> Tip: See [Query Builder](db-query-builder.md) and especially [Filter Conditions](db-query-builder.md#filter-conditions)
> to learn how to build filtering query.
You can use this function in the controller to get the dataProvider for the GridView: You can use this function in the controller to get the dataProvider for the GridView:
```php ```php