Download the PHP package cocept/filter without Composer
On this page you can find all versions of the php package cocept/filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cocept/filter
More information about cocept/filter
Files in cocept/filter
Package filter
Short Description Lets you filter Doctrine queries in Symfony using a widget which sets url parameters. Plays nicely with KNP Paginator.
License MIT
Informations about the package filter
Cocept Filter
Cocept Filter is a bundle for Symfony and Doctrine that lets users filter datasets using a select widget.
The bundle provides a service and a widget. The widget shows the user a search input or select box which when changed inserts the appropriate filter options into the URL. The filter service gets the filter options from the URL and adds where clauses to the query builder to filter the results.
Multiple filters can be applied, and operators can also be specified. This bundle plays nicely with KNP Paginator.
Demo Application
You can use this symfony demo application to see the filter bundle in action:
https://github.com/cocept/filter-test
Installation
Install with composer
Load the bundle
Add the bundle to your application kernel:
Apply the filter in your controller
Find the index action of the controller you want to filter and add the following line:
The third parameter should be an array containing a list of regular fields (string, int etc) that the user is allowed to filter.
The fourth parameter should be an array containing a list of foreign key fields that the user is allowed to filter.
Add the widget to your twig template
In your twig template, add the following line:
The first parameter of the filterWidget function should be the field on which to filter.
If the second parameter is omitted, the user will be shown a search field and the ilike operator will be used. Otherwise, an associative array must be provided and the user will see a select box and a button to toggle between the eq and neq operators. The array key will be used as the option label and the value as the option value.
So, if you want to show the user a list of category names, the array would be something like this:
Load the JavaScripts
The filterWidget twig extension uses a javascript file to add the filter options to the URL parameters. Add the following to the head section of your twig template:
Try it out
The widget adds URL parameters like filter_name=someval, where name is the column name and someval is the value to match. You can also add operator_name=neq, where name is the column and neq is the operator to use in the where clause, with the following mappings:
- neq: !=
- ilike: ilike
- eq: =
An example URL with filter parameters might be:
Contributing
This bundle is actively used in production and will be maintained as such. If you wish to submit a pull request it will be promptly considered and merged.
All versions of filter with dependencies
symfony/framework-bundle Version ~2.3|~2.8
twig/twig Version ~1.12|~2
symfony/assetic-bundle Version ^2.7