PHP code example of brenoroosevelt / cakephp-filter

1. Go to this page and download the library: Download brenoroosevelt/cakephp-filter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brenoroosevelt / cakephp-filter example snippets


Plugin::load('BRFilter');

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));
    	
    	// ...
}

	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();