Skip to content

Commit

Permalink
Update doc examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Sep 13, 2023
1 parent 1dd6df2 commit dc31898
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/basic-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function index()
$query = $this->Posts
// Use the plugins 'search' custom finder and pass in the
// processed query params
->find('search', ['search' => $this->request->getQueryParams()])
->find('search', search: $this->request->getQueryParams())
// You can add extra things to the query if you need to
->contain(['Comments'])
->where(['title IS NOT' => null]);
Expand Down
12 changes: 2 additions & 10 deletions docs/filter-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ Let's use the *backend*'s filters by doing:
```php
// PostsController::action()
$query = $this->Examples
->find('search', [
'search' => $this->request->getQueryParams(),
'collection' => 'backend',
]);
}
->find('search', search: $this->request->getQueryParams(), collection: 'backend');
```

## Filter collection classes
Expand Down Expand Up @@ -85,11 +81,7 @@ You can also specify alternate collection class to use when making find call:
```php
// PostsController::action()
$query = $this->Posts
->find('search', [
'search' => $this->request->getQueryParams(),
'collection' => 'posts_backend',
]);
}
->find('search', search: $this->request->getQueryParams(), collection: 'posts_backend');
```

The above will use `App\Model\Filter\PostsBackendCollection`.
Expand Down
12 changes: 6 additions & 6 deletions docs/filters-and-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $searchManager->exists('nullable_field');

----------

`Finder` to produce results using a [(custom)](https://book.cakephp.org/4/en/orm/retrieving-data-and-resultsets.html#custom-find-methods) finder
`Finder` to produce results using a [(custom)](https://book.cakephp.org/5/en/orm/retrieving-data-and-resultsets.html#custom-find-methods) finder

```php
// executes the findMyFinder() method in your table class
Expand All @@ -69,7 +69,7 @@ should return bool to specify `isSearch()` (useful when using with `alwaysRun` e
```php
// Completely up to your code inside the callback
$searchManager->callback('category_id', [
'callback' => function (\Cake\ORM\Query $query, array $args, \Search\Model\Filter\Base $filter) {
'callback' => function (\Cake\ORM\Query\SelectQuery $query, array $args, \Search\Model\Filter\Base $filter) {
// $args contains the values given in the request
// $query->where([]);
return true;
Expand Down Expand Up @@ -117,7 +117,7 @@ The following options are supported by all filters.
// PostsTable::initialize()
$searchManager->like('q', [
'fields' => ['Posts.title', 'Authors.title'],
'beforeProcess' => function (\Cake\ORM\Query $query, array $args, \Search\Model\Filter\Base $filter) {
'beforeProcess' => function (\Cake\ORM\Query\SelectQuery $query, array $args, \Search\Model\Filter\Base $filter) {
$query->contain('Authors');
},
]);
Expand Down Expand Up @@ -246,9 +246,9 @@ your best option is to use a `callback` like so:
```php
$searchManager
->callback('category_id', [
'callback' => function (\Cake\ORM\Query $query, array $args, \Search\Model\Filter\Base $filter) {
'callback' => function (\Cake\ORM\Query\SelectQuery $query, array $args, \Search\Model\Filter\Base $filter) {
$query
->innerJoinWith('Categories', function (\Cake\ORM\Query $query) use ($args) {
->innerJoinWith('Categories', function (\Cake\ORM\Query\SelectQuery $query) use ($args) {
return $query->where(['Categories.id IN' => $args['category_id']]);
})
->group('Products.id');
Expand Down Expand Up @@ -309,7 +309,7 @@ class MyCustomFilter extends \Search\Model\Filter\Base
/**
* @return bool
*/
public function process()
public function process(): bool
{
// return false if you want to skip modifying the query based on some condition.

Expand Down

0 comments on commit dc31898

Please sign in to comment.