Git Product home page Git Product logo

filtermanager's Introduction

FilterManager for Laravel 5

Filter manager package for product list,let`s elegant generate filter url. This page used FilterManager: kiteme.cn/list

中文文档

demo image

demo image

Installation

{
  "require": {
    // ...
    "toplan/filter-manager": "dev-master",
   }
}

Usage

To use the FilterManager Service Provider, you must register the provider when bootstrapping your Laravel application. There are essentially two ways to do this.

1. The preparatory work

Find the providers key in config/app.php and register the FilterManger Service Provider.

    'providers' => array(
        // ... 
        'Toplan\FilterManager\FilterManagerServiceProvider',
    )

Find the aliases key in config/app.php.

    'aliases' => array(
        // ...
        'FilterManager' => 'Toplan\FilterManager\Facades\FilterManager',
    )

2. then, Just enjoy it

<!-- example -->
<li class="item all {{FilterManager::isActive('gender',\Toplan\FilterManager\FilterManager::ALL,'active','')}}">
  <a href="{{FilterManager::url('gender',\Toplan\FilterManager\FilterManager::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>

Commonly used method

You can find most of the usage in the this file: demo_temp_for_laravel.balde.php

  • create a instance of FilterManager.

create($filters,$baseUrl,$blackList);

$filters: this is filters data ,required,exp:['gender'=>'male','city'=>'beijing']

$baseUrl: default=array().

$blackList: this is blacklist for filtrs,default=array(),exp:['pageindex'].

  • set black list for filter

setBlackList($filter_name_array)

   FilterManager::setBlackList(['page','pageindex']);
  • has filter,return value or false

has($filter_name)

   FilterManager::has('gender');
  • is active

isActive($filter_name, $filter_value, $trueReturn, $falseReturn)

   FilterManager::isActive('gender','male');#this will return true or false;
   FilterManager::isActive('gender','male','active','not active');#this will return 'active' or 'not active';
  • get url

url($filter_name,$filter_value,$multi,$LinkageRemoveFilters,$blackList)

One filter has some values,and every value has a url,this mothod return a full url string.

$filter_name: param name, required.

$filter_value: param value, default value:\Toplan\FilterManager\FilterManager::ALL.

$multi: whether to support multiple? false or true, default=false.

$LinkageRemoveFilters:linkage remove the other filter, default=array().

$blackList: temporary blacklist, default=array().

   FilterManager::url('gender',\Toplan\FilterManager\FilterManager::ALL);//without gender param
   
   FilterManager::url('gender','male',false);#single value

   FilterManager::url('cities','beijing',true);#multiple values
   
   //One province has many cities,If you remove the 'province tag',you should linkage remove the selected cities
   FilterManager::url('province','chengdu',false,['cities']);//linkage remove selected cities

filtermanager's People

Contributors

toplan avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.