PHP code example of toplan / filter-manager

1. Go to this page and download the library: Download toplan/filter-manager 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/ */

    

toplan / filter-manager example snippets


composer 


use Toplan\FilterManager\FilterManager as FilterManager;

// params
$paramsArray = [
    'paramName' => 'value',
    ...
]

// create instance by yourself.
$fm = FilterManager::create($paramsArray)->setBlackList(['page']);

//then, render `$fm` value to your template!

    'providers' => array(
        Toplan\FilterManager\FilterManagerServiceProvider::class,
    )

    'aliases' => array(
        'FilterManager' => Toplan\FilterManager\Facades\FilterManager::class,
    )

$fm->setBlackList(['page', 'pageindex']);
//or in laravel
FilterManager::setBlackList(['page', 'pageindex']);

$value = $fm->has('gender');

//or in laravel
$value = FilterManager::has('gender');

//in laravel
FilterManager::isActive('gender', 'male');//this will return true or false;

FilterManager::isActive('gender', 'male', 'active', '');//this will return 'active' or '';

//in laravel
FilterManager::url('gender', FM_SELECT_ALL);//without gender param

FilterManager::url('gender', 'male', false);//single value

FilterManager::url('cities', 'shanghai', true);
FilterManager::url('cities', 'beijing', true);//multiple values

// One province has many cities, one city has many counties ...,
// If you select 'all province' or one of provinces,
// you should linkage remove the selected cities and counties ...
//
// like this:
// select all province
FilterManager::url('province', FM_SELECT_ALL, false, ['cities', 'counties', ...]);//linkage remove selected cities
// select one province
FilterManager::url('province', 'sichuan', false, ['cities', 'counties', ...]);//linkage remove selected cities