Download the PHP package opwoco/query-filter-bundle without Composer
On this page you can find all versions of the php package opwoco/query-filter-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package query-filter-bundle
Master |
---|
Query Filter Bundle
Query Filter Bundle brings request filtering and pagination functionality to Symfony 4 applications that use Doctrine 2.
Installation
First, install the dependency:
Usage examples
Basic example
-
Controller
- Repository
Now you can start your php server and filter the requests:
This request will perform a LIKE request in DQL:
Advanced example
This filtering library is best used together with JMSSerializerBundle and FOSRestBundle. You will eventually write a lot less code that it was shown in the basic example.
To utilize the advanced usage, install all the packages.
- Turn them on in
config/bundles.php
:
NOTE: you may need to add further bundles depending on your set up for FOSRestBundle and/or JMSSerializerBundle.
-
Controller:
- Repository:
ItemConfig:
Simple Query Filter Examples
NOTE: assume that all the used fields are enabled in the configuration
- Performs
t.name LIKE
%doe% comparison - Performs
t.name = "Doe"
comparison - Performs
t.name <> "Doe"
comparison - Performs
t.name LIKE "Doe"
comparison - Performs
t.name NOT LIKE "Doe"
comparison - Performs
t.frequency BETWEEN 8 AND 10
comparison - Performs
t.frequency NOT BETWEEN 8 AND 10
comparison - Performs
t.frequency > 7
comparison - Performs
t.frequency >= 7
comparison - Performs
t.frequency IN (1, 2, 3, 4, 5)
comparison - Performs
t.frequency NOT IN (1, 2, 3, 4, 5)
comparison - Performs
t.description IS NULL
comparison - Performs
t.description IS NOT NULL
comparison - Performs
t.frequency < 7
comparison - Performs
t.frequency <= 7
comparison - Combined comparison
t.frequency < 7 AND t.monetary > 50
Advanced Query Filter Example
Simple mode should be enough for most of the cases, however sometimes we might need to build more complicated filters having one and the same field used.
- Performs
t.frequency = 10 OR t.frequency >= 85
(NOTE:filter[1][connector]=or
-connector
can beand
(default) oror
; connector used on the first filter has no effect)
Pagination Examples
- Second page (NOTE: if
page
is not given it defaults to 1) - Limit records to 100 (NOTE: if default limits were provided and
limit
is not within the allowed values, it will be reset to the default value)
Sorting Example
- Performs
ORDER BY t.userId DESC
(ifsortdir
is not given it defaults toasc
)
NOTE: at the moment this bundle doesn't support more than one field for ORDER BY
.
This document is not finished yet, more examples will follow.
Code license
You are free to use the code in this repository under the terms of the MIT license. LICENSE contains a copy of this license.