All symfony lovers know that there is no filter component in it.
There are wonderful and convenient Constraints and there was even an attempt to create a similarity to their issue filters on Github , but no one took it.
When I once again faced the task of filtering a large amount of data received from the user, I realized that it was time to solve the filtering problem as something more globally / beautiful / convenient.
Having carried out a certain research, I realized that nothing fundamentally new in filtering for php appeared. There are 2 popular components:
Please note that the latter is not quite well supported by the author .
For DMS-Filter there is a symfony bundle but it is not compatible with symfony 3. Yes, and I did not like the code, since I understood that you can make everything a bit simpler.
After analyzing the situation, I realized that the fastest and most reliable way to write a bundle for filtering will be using well-documented and test-covered filters from Zend Filter. I also want to add that in the past I worked a lot with Zend Framework 1 and they were close and clear to me.
I wanted to make the logic of the work of filters like Symfony Constraints.
As a result, a bundle was written that adds a service that can be used to filter an object based on annotations. In addition, a bundle can filter forms if it finds an annotated object.
In the process of writing the module difficulties did not arise. Here are the sections of the documentation that I used at the time of writing:
It seems to me it is not necessary to describe in detail how to use the bundle in this publication as it explains more why I wrote it. And it’s strange to just copy information from one place to another.
Documentation on using bundla and the bundle itself can be found on the FilterBundle GitHub.
I would like to know from the community, and how do you solve filtering tasks in symfony?
Source: https://habr.com/ru/post/281863/
All Articles