Declarative query filtering for CakePHP index actions. Map form input keys to table finders and apply them to a query in a single call, keeping controllers free of filter plumbing.
- PHP >= 8.2
cakephp/cakephp^5.0
composer require arodu/cakephp-query-filter:^3.0
Load the plugin in src/Application.php:
$this->addPlugin(\QueryFilter\QueryFilterPlugin::class);// In the table's initialize() (or a setup method)
$this->addBehavior('QueryFilter.QueryFilter', [
'filterFields' => [
'name' => ['tableField' => 'name', 'finder' => \QueryFilter\QueryFilter::FINDER_STRING],
'status' => ['tableField' => 'status', 'finder' => \QueryFilter\QueryFilter::FINDER_SELECT],
],
]);
// In the controller action
$behavior = $this->Students->getBehavior('QueryFilter');
$query = $behavior->queryFilter($this->Students->find(), $this->request->getQuery('f') ?? []);- Usage — registering filters and applying them.
- Finders reference — every finder, its arguments and examples.
- Templates — building field/value conditions.
- Events —
beforeFilter,afterFilter,beforeFinder,afterFinder.
MIT