PHPackages                             brenoroosevelt/cakephp-filter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. brenoroosevelt/cakephp-filter

ActiveCakephp-plugin[Utility &amp; Helpers](/categories/utility)

brenoroosevelt/cakephp-filter
=============================

Filter plugin for CakePHP 3.x

1.0.0(9y ago)11.0k3[2 issues](https://github.com/brenoroosevelt/cakephp-filter/issues)MITPHPPHP &gt;=5.5.9

Since Jan 25Pushed 5y agoCompare

[ Source](https://github.com/brenoroosevelt/cakephp-filter)[ Packagist](https://packagist.org/packages/brenoroosevelt/cakephp-filter)[ RSS](/packages/brenoroosevelt-cakephp-filter/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Filter plugin for CakePHP 3.x
=============================

[](#filter-plugin-for-cakephp-3x)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](README.md)[![Total Downloads](https://camo.githubusercontent.com/23a6e91f7bac02dcee5110ea60001b5b3c02ccf1e2de9821fc26a7236096c9e9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6272656e6f726f6f736576656c742f63616b657068702d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/brenoroosevelt/cakephp-filter)[![Latest Stable Version](https://camo.githubusercontent.com/76e50bd3b083d91859ff48d123cdb246cebdec4b4bd1693932f2a0e622f29947/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6272656e6f726f6f736576656c742f63616b657068702d66696c7465722e7376673f7374796c653d666c61742d737175617265266c6162656c3d737461626c65)](https://packagist.org/packages/brenoroosevelt/cakephp-filter)[![Build Status](https://camo.githubusercontent.com/216aee165eb9d8bfdcd213e7494dd35bca851d0fbfa5973dced6f682b82dbce9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6272656e6f726f6f736576656c742f63616b657068702d66696c7465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/brenoroosevelt/cakephp-filter)[![Coverage Status](https://camo.githubusercontent.com/6efa62434211fd25e0fc7ab285a4819899b3aea0a016186f2e972a92add3e30d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6272656e6f726f6f736576656c742f63616b657068702d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/brenoroosevelt/cakephp-filter)

Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require brenoroosevelt/cakephp-filter

```

### Load the plugin

[](#load-the-plugin)

Add following to your `config/bootstrap.php`

```
Plugin::load('BRFilter');
```

Usage
-----

[](#usage)

### Controller class

[](#controller-class)

```
public function index()
{
		$this->loadComponent('BRFilter.Filter');

		// add filter and options
		$this->Filter->addFilter([
					'filter_id' => ['field' => 'Posts.id', 'operator'=>'='],
					'filter_title' => ['field' => 'Posts.title', 'operator' => 'LIKE', 'explode' => 'true'],
					'filter_category_id' => ['field'=> 'Posts.category_id', 'operator' => 'IN' ]
		]);

		// get conditions
		$conditions = $this->Filter->getConditions(['session'=>'filter']);

		// set url for pagination
    	$this->set('url', $this->Filter->getUrl());

    	// apply conditions to pagination
    	$this->paginate['conditions']	= $conditions;

    	// get pagination
    	$this->set('posts', $this->paginate($this->Posts));

    	// ...
}
```

### Template views

[](#template-views)

You have to add a form to your index.ctp, corresponding with the alias of your filter configuration.

```
	echo $this->Form->create();

   	// Match with the filter configuration in your controller
    echo $this->Form->input('filter_id', ['type' => 'text']);
    echo $this->Form->input('filter_title', ['type' => 'text']);
    echo $this->Form->input('filter_category_id', ['options'=>[ /* ... */ ], 'multiple'=>'multiple' ]);

	echo $this->Form->button('Filter', ['type' => 'submit']);
	echo $this->Form->end();
```

### Filter options

[](#filter-options)

The following options are supported:

- `field` (`string`) The name of the field to use for searching.
- `operator` (`string`) The operator used for searching.
- `explode` (`boolean`) Used only with operator `LIKE` and `ILIKE` to explode the string query.

### Operators

[](#operators)

The following options are supported:

- `=`
- `>`
- `=`
- `
