Filter manager package for product list,elegant generate url.
A filter manager package for the product list filter, help you elegant generate filter url., (*1)
中文文档, (*2)
, (*3)
composer require 'ajiader/filter-manager:~1.0.4'
require 'path/to/vendor/autoload.php'; 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!
Or used in laravel just like this:, (*4)
Find the providers key in config/app.php and register the FilterManger Service Provider., (*5)
'providers' => array( Toplan\FilterManager\FilterManagerServiceProvider::class, )
Find the aliases key in config/app.php., (*6)
'aliases' => array( 'FilterManager' => Toplan\FilterManager\Facades\FilterManager::class, )
use value $fm
in template:, (*7)
<!-- example --> <li class="item all {{$fm->isActive('gender', FM_SELECT_ALL, 'active', '')}}"> <a href="{{$fm->url('gender', FM_SELECT_ALL)}}">All</a> </li> <li class="item @if($fm->isActive('gender', 'male')) active @endif"> <a href="{{$fm->url('gender', 'male')}}">Male</a> </li> <li class="item @if($fm->isActive('gender', 'female')) active @endif"> <a href="{{$fm->url('gender', 'female')}}">Female</a> </li>
or use laravel facade value FilterManager
in template:, (*8)
<!-- example --> <li class="item all {{FilterManager::isActive('gender', FM_SELECT_ALL, 'active', '')}}"> <a href="{{FilterManager::url('gender', FM_SELECT_ALL)}}">All</a> </li> <li class="item @if(FilterManager::isActive('gender', 'male')) active @endif"> <a href="{{FilterManager::url('gender', 'male')}}">Male</a> </li> <li class="item @if(FilterManager::isActive('gender','female')) active @endif"> <a href="{{FilterManager::url('gender', 'female')}}">Female</a> </li>
create a instance., (*9)
$filters
: this is filters data, required, exp:['gender'=>'male', 'city'=>'beijing'], (*10)
$baseUrl
: default value is empty string., (*11)
$blackList
: this is blacklist for filters, default value is []
, exp:['pageindex']., (*12)
set black list for filter., (*13)
example:, (*14)
$fm->setBlackList(['page', 'pageindex']); //or in laravel FilterManager::setBlackList(['page', 'pageindex']);
whether has the character filter, if true will return the value, if don`t return false., (*15)
example:, (*16)
$value = $fm->has('gender'); //or in laravel $value = FilterManager::has('gender');
example:, (*17)
//in laravel FilterManager::isActive('gender', 'male');//this will return true or false; FilterManager::isActive('gender', 'male', 'active', '');//this will return 'active' or '';
One filter has some values, and every value has a url, this method return a full url string., (*18)
$filterName
: param name, required., (*19)
$filterValue
: param value, default value is FM_SELECT_ALL
., (*20)
$multi
: whether to support multiple values? false
or true
, default value is false
., (*21)
$linkageRemoveFilters
:linkage remove the other filter, default value is []
., (*22)
$blackList
: temporary blacklist, default value is []
., (*23)
example:, (*24)
//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