Download the PHP package pacolmg/symfony-filter-bundle without Composer

On this page you can find all versions of the php package pacolmg/symfony-filter-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package symfony-filter-bundle

Symfony Filter Bundle

This bundle provides your Symfony 4 app some functions to filter and make lists in an easy way.

License MIT

Installation

Add the package to composer via console

Add the Bundle to config/bundles.php

Probably you can skip this step, because Symfony Flex do it automatically. But just in case, go to the file config\bundles.php and check that this line is in the code:

Extend the Repository of the entity that need to be filtered

For instance, in a entity called Article, with a repository that should be in src\Repository\ArticleRepository.php:

Now, the installation is finished and the Article repository will have new methods in order to find objects filtered by different fields and in different ways (like, greater than, ...)

Multiple repositories can be extended.

Usage

Start Filtering the Repository

Method getAll

To filter the objects method getAll from the repository extended should be called:

Parameters

The parameter $filter

It's the only mandatory parameter, and is composed by an array of different filters with the format:

**The field is allow to have multiple values separated by a pipe | to search the same value in more than one field.

Type of filters

Method getAllCount

If the number of the results is needed, the method getAllCount will return that number, just the pass the filters to the method.

Examples

So, after this explanation of the filters that can be used, if we need the articles where has the word tree in its title, we should code:

Easy? So, now, we are gonna find the articles with a tree in the title and a cat in the title or in the body:

Too many results? If it's up to you, we will sort the results by publishDate and filter them, because we are only interested in the current year:

Are there still many results? We should paginate it, we want to see the second page, showing 10 results per page:

If your are showing the results on a website, it's probably that you need the total number or elements in order to show it or to make a proper pagination, easy:

Method getDistinctField

Maybe the different values of a field are needed for filter a select, call the function with the name of the field as parameter.

Examples

We need all the different authors of the entity to put them on a select:

Filter using the Service

The bundle provide you a service: Pacolmg\SymfonyFilterBundle\Service\FilterService;

Within this service the methods of the repository getAll and getAllCount are joined, so the method getFiltered from the Service will return the Collection of Objects from the repository and the total number of elements to help the controller and view make the pagination.

The sort parameter has a different format in order to pass the field and the direction, avoiding code an array.

Examples

The last of the examples, coding from a Service or a Controller could be:

This example will return an array with two keys:

Filter from the Controller

To make a complete integration with a Website, the bundle provide another Service Pacolmg\SymfonyFilterBundle\Service\ExternalParametersService where there are some methods to get parameters from a Request.

Get Page and Limit

The method getPageAndLimit returns in an array the page and the number of elements per page. It gets the information from the parameters page and limit.

Examples

In the Controller we can code this and the variable $page and $limit will have the page and the number of elements per page, the minimum page is 1 and the maximum limit is 500.

list($page, $limit) = $this->externalParametersService->getPageAndLimit($request);

Get Filters

The method getFilters needs the $request and the $filters and will return the value for them, in order to make it work, we need to add a pair of fields to each filter:

Request Types

The types of the request_type can be:

Examples

We have have a website with a search input that send the controller a parameter t with the value of the input, and we want to use this to look for a title like the parameter t:

http://mywebsite.com?t=tree

In the Controller we should code:

In the next example we have parameters for the pagination:

http://mywebsite.com?t=tree&page=2&limit=10

So, this will be the code in the Controller:

Filter from the View

The bundle wants to help you with the form in the view too, so you can include some fields that are predefined, or extend your complete form "@PacolmgSymfonyFilter/filters/layout.html.twig":

Inputs

The predefined fields are:

Parameters

Each input has some common parameters:

The select field type will have another two parameters, one of them mandatory:

Examples

We still want to find the articles which title has a certain word that we will collect from an input in the view. And we also want them filtered between two dates and by status too, so an example of form could be:

This form will send the parameters just to catch them coding this:

Imagine you change your mind and prefer to get the articles that can be published or created, so we need to convert the status select to multiple:

And on the controller, change the type of the filter:

Pagination

So, at the Controller, Service and Repository is possible to get the results paginated. The bundle has also a twig to make pagination easy for development. Just include the '@PacolmgSymfonyFilter/components/pagination.html.twig' view and see the pages.

Parameters

The mandatory parameters are:

The twig has some optional parameters too:

Examples

We have our article index page where we have the filters defined in the previous examples, now we want to show the number of the pages:

To avoid too much logic on the twig, we construct the parameters in the Controller:

In the view:

Hope that filter and paginate your entities with this bundle will not be a pain anymore.


All versions of symfony-filter-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1.3
symfony/config Version ^3.4 || ^4.0 || ^4.3 || ^4.4
symfony/dependency-injection Version ^3.4 || ^4.2 || ^4.3 || ^4.4
symfony/http-kernel Version ^3.4 || ^4.0 || ^4.3 || ^4.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pacolmg/symfony-filter-bundle contains the following files

Loading the files please wait ....