Skip to content

About

QueryFilter plugin for CakePHP

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

27 Commits

Folders and files

Repository files navigation

QueryFilter plugin for CakePHP

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.

Requirements

  • PHP >= 8.2
  • cakephp/cakephp ^5.0

Installation

composer require arodu/cakephp-query-filter:^3.0

Load the plugin in src/Application.php:

$this->addPlugin(\QueryFilter\QueryFilterPlugin::class);

Quick start

// 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') ?? []);

Documentation

  • Usage — registering filters and applying them.
  • Finders reference — every finder, its arguments and examples.
  • Templates — building field/value conditions.
  • Events — beforeFilter, afterFilter, beforeFinder, afterFinder.

License

MIT

About

QueryFilter plugin for CakePHP

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages