Provided filter types
TextFilterType, NumberFilterType, DateRangeFilterType, EntityFilterType and more — drop-in replacements for the core Symfony form types.
Browse the types
Build a filter form the way you build any other Symfony form, and let the bundle translate it into WHERE clauses on your query builder.
TextFilterType, NumberFilterType, DateRangeFilterType, EntityFilterType and more — drop-in replacements for the core Symfony form types.
Browse the types
Filter across Doctrine associations and embeddables by nesting filter form types and declaring the joins you need.
Learn more
Remember a filter across requests, turn it into a shareable permalink, or store it as a named preset — all opt-in.
Read the guide
See exactly which form field produced which DQL condition, and why a field was silently ignored.
Debug a filter
Follow a filter form from PHP definition to rendered fields, DQL and matching records.
Try the demo
composer require spiriitlabs/form-filter-bundleCreate a filter form using the bundle's filter types instead of the plain Symfony ones:
<?php
namespace Project\Form\Filter;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Spiriit\Bundle\FormFilterBundle\Filter\Form\Type as Filters;
class RankFilterType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', Filters\TextFilterType::class);
$builder->add('rank', Filters\NumberFilterType::class);
}
}Then build the query from the submitted form:
class DefaultController extends AbstractController
{
public function __invoke(
Request $request,
FormFactoryInterface $formFactory,
EntityManagerInterface $em,
FilterBuilderUpdater $filterBuilderUpdater
): Response
{
$form = $formFactory->create(RankFilterType::class);
$form->handleRequest($request);
$filterBuilder = $em
->getRepository(MyEntity::class)
->createQueryBuilder('e');
$filterBuilderUpdater->addFilterConditions($form, $filterBuilder);
// now look at the DQL =)
dump($filterBuilder->getDql());
return $this->render('testFilter.html.twig', [
'form' => $form,
]);
}
}