Download the PHP package codekanzlei/cake-list-filter without Composer
On this page you can find all versions of the php package codekanzlei/cake-list-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codekanzlei/cake-list-filter
More information about codekanzlei/cake-list-filter
Files in codekanzlei/cake-list-filter
Package cake-list-filter
Short Description List Filter Component / Helper for easy CRUD lists
License MIT
Informations about the package cake-list-filter
A CakePHP 3 plugin which provides an easy way to create filters for CRUD lists. The plugin will dynamically render the markup necessary and manipulate the controller's $paginate
config dynamically.
Installation
composer require "codekanzlei/cake-list-filter": "dev-master"
In your App's config/bootstrap.php
load the plugin:
In your AppController, or in the controller where you'd like to use ListFilter, load the ListFilterComponent
and ListFilterHelper
.
Usage
You define filterable fields right in the controller where the pagination happens. This ensures that only the fields you configured can be used for searching, also this automates the generation of the form necessary.
You can either define the fields as the $listFilter
property in your controller, or implement a getListFilters() callback method.
Multiple listFilters in one controller are possible, as the config is separated by the controller action. In this example we assume you want to have a ListFilter in your controller action index
.
Configuring the ListFilters via the callback method provides more flexibility, as it allows to have code executed, which is not possible in a class property.
We assume that the index
controller action looks like this:
Now, in your index.ctp
view file you can render the filter box like this:
Your filter box will look like this:
Options
searchType
This can be one of the following:
wildcard
: Executes a LIKE search with the given stringselect
: Renders a dropdown containing the options of theoptions
config key. Only keys from this array config can be used to filter, so no URL manipulation is possible.multipleselect
: Analog to select, but renders a dropdown with multiple selection.fulltext
: Will split the given search term by whitespace and makes sure that all the terms are present in the field via LIKE.searchFields
: If this array is specified, multiple fields will be searchedtermsCallback
: A callback function which receives an array containing the search terms and must return an array. Can be used to influence search logic.
inputOptions
These options will be used to render the form field using FormHelper::input()
. So in here, you can set the label, add classes to the input, etc.
searchTermsConjunction
Setting up the component, you may give an additional options array to overwrite the default config. Especially interesting is searchTermsConjunction, which is 'AND' by default and means, that multiple terms in a fulltext search will be added to the pagination conditions with an AND conjunction between them to narrow down the search results.
If you wish to broaden the results by connecting the terms with OR, you can setup the component like so:
Handling many-to-many relations
To handle many-to-many relations, like Users BelongsToMany Groups, you have to build a custom query and pass it to the Paginator, as the Paginator by default can't handle many-to-many relations.
Customization
If you need a custom layout for your filterbox, you can construct the filter box individually like you please. Every element of the listFilter can be rendered individually:
Also, you can manipulate default templates and classes used by calling ListFilterHelper::config() with your overrides. These are the options available: