Skip to content

Commit 9b4f483

Browse files
authored
Update optional-conditions.md
1 parent 9ff9da6 commit 9b4f483

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

doc/optional-conditions.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Optional conditions
22

3+
Sometimes you want to set conditions based on dynamic data. One example would be a grid-list with dynamic filters for certain columns. Following the example below, you can predefine _optional conditions_ which will execute when the corresponding data in the `$filter`-Array is present.
4+
35
```PHP
46
$filter = [
57
'name' => 'Peter',
@@ -9,15 +11,13 @@ $filter = [
911
],
1012
];
1113

12-
$req = new RequiredFilterMap($filter);
13-
$opt = new OptionalFilterMap($filter);
14-
1514
$query = $db
1615
->from('t', 'test')
17-
->where($req('t.name=?', $filter, 'name'))
18-
->where($opt('t.date >= ?', $filter, 'date.start')) // Key in dot-notation
19-
->where($opt('t.date <= ?', $filter, ['date', 'end'])) // Array-Key
16+
->where(new DBExprFilter('t.name = ?', $filter, 'name'))
17+
->where(new DBExprFilter('t.date >= ?', $filter, 'date.start')) // Key in dot-notation
18+
->where(new DBExprFilter('t.date <= ?', $filter, ['date', 'end'])) // Key in array-notation
2019
```
2120

21+
You can also define validation rules to only match certain data in `$filter`.
2222

2323
[Back](../README.md)

0 commit comments

Comments
 (0)