PHPackages                             simtecsystem/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. simtecsystem/cakephp-filter

ActiveCakephp-plugin

simtecsystem/cakephp-filter
===========================

Filter plugin for CakePHP &gt;3.6

1.1.1(7y ago)013MITPHPPHP &gt;=5.5.9

Since Jan 25Pushed 7y agoCompare

[ Source](https://github.com/simtecsystem/cakephp-filter)[ Packagist](https://packagist.org/packages/simtecsystem/cakephp-filter)[ RSS](/packages/simtecsystem-cakephp-filter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

Filter plugin for CakePHP &gt;3.6.x
===================================

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

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](README.md)[![Total Downloads](https://camo.githubusercontent.com/4a46df78b82f1dd72a0bd3ac36bf140e08be45fbec2700ea141014d83a08eef0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73696d74656373797374656d2f63616b657068702d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/simtecsystem/cakephp-filter)[![Latest Stable Version](https://camo.githubusercontent.com/79e669c9ebe488a21ec443b4b3ecc5ad573647722c378754b917efe5fa4ab3d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73696d74656373797374656d2f63616b657068702d66696c7465722e7376673f7374796c653d666c61742d737175617265266c6162656c3d737461626c65)](https://packagist.org/packages/simtecsystem/cakephp-filter)[![Build Status](https://camo.githubusercontent.com/0fae7aff8557910f6cc1fa53c220a04570645bfe77439c0ccfd7a9a1aa69305b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73696d74656373797374656d2f63616b657068702d66696c7465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/simtecsystem/cakephp-filter)[![Coverage Status](https://camo.githubusercontent.com/b6eae67b2f3adc1a97cad8b18dc747cd5b0cf66c93572b9815779489f3ce3e15/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f73696d74656373797374656d2f63616b657068702d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/simtecsystem/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 simtecsystem/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:

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