PHPackages                             samson/filter-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. samson/filter-bundle

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

samson/filter-bundle
====================

4.0.1(10y ago)2968[7 issues](https://github.com/SamsonIT/FilterBundle/issues)PHP

Since Jan 21Pushed 8y ago14 watchersCompare

[ Source](https://github.com/SamsonIT/FilterBundle)[ Packagist](https://packagist.org/packages/samson/filter-bundle)[ RSS](/packages/samson-filter-bundle/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (13)Used By (0)

Implement a filter in a Symfony Controller
==========================================

[](#implement-a-filter-in-a-symfony-controller)

Step1: your FilterData-object
=============================

[](#step1-your-filterdata-object)

Filterparams are defined in a FilterData-object, it's a POPO:

```
namespace Foo\Bar\Form\Filter;

use Samson\FilterBundle\Filter\Search as Filter;

class CompanyFilter {
  /**
   * @Filter\IntegerFieldSearch(propertyPath="id")
   */
  private $id;

  /**
   * @Filter\StringFieldSearch()
   */
  private $name;

  public function getId() {
    return $this->id;
  }

  public function setId($id) {
    $this->id = $id;
  }

  public function getName() {
    return $this->name;
  }

  public function setName($name) {
    $this->name = $name;
  }
}
```

**Please note the use-statement**

Options (all)
=============

[](#options-all)

- propertyPath (the path to the filtered property, e.g. "person.lastName". It's optional, by default it takes the name of the variable)
- propertyPaths(same as propertyPath, but used for collections. E.g. "addresses.city" to find city-names in a collection of Addresses)

StringFieldSearch
=================

[](#stringfieldsearch)

Options (default: type):

- type ('contains', 'begins\_with', 'ends\_with', 'equals')

IntegerFieldSearch
==================

[](#integerfieldsearch)

Options (default: type):

- type ('equals'/'=', 'is less than'/'&lt;', 'is less than or equal to'/'&lt;=', 'is greater than'/'&gt;', 'is greater than or equal to'/'&gt;=', 'is not equal to'/'&lt;&gt;')

Step 2: FilterType (the Form)
=============================

[](#step-2-filtertype-the-form)

Define a Form to glue your FilterData-object to.

```
namespace Foo\Bar\Form\Filter;

use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\AbstractType;

class CompanyFilterType extends AbstractType {
  public function buildForm(FormBuilder $builder, array $options) {
    $builder
      ->add('id', null, array('required'=>false))
      ->add('name', null, array('required'=>false))
    ;
  }

  public function getName() {
    return 'company_filter';
  }

  public function getDefaultOptions(array $options) {
    return array(
      'data_class' => 'Foo\Bar\Form\Filter\CompanyFilter'
    );
  }
}
```

**Please note the data\_class option. It's necessary to add this, otherwise the values cannot be stored**

Step 3: Usage in your Controller
================================

[](#step-3-usage-in-your-controller)

Create a Form like any other form:

```
$filter = $this->createForm('filter', null, array(
  'filter_type' => new CompanyFilterType(),
  'filter_data' => new CompanyFilter()
));
```

Create the QueryBuilder you are going to use to fetch filtered entities:

```
$qb = $em->getRepository('FooBundle:Company')->createQueryBuilder('b')->orderBy('b.id');
$this->get('samson.filter')->bindAndfilter($this->getRequest(), $filter, $qb);
```

Step 4: Create your view
========================

[](#step-4-create-your-view)

Create the view of your form in a Twig-template. No need for a submit button.

```

{{ form_widget(filter) }}

```

Override the inner part of your Filter like this:

```
{% block company_filter_widget %}

        {% for field in form %}
            {{ form_row(field) }}
        {% endfor %}

{% endblock %}
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~83 days

Recently: every ~127 days

Total

11

Last Release

3651d ago

Major Versions

1.0.x-dev → 2.0.02014-03-20

2.0.x-dev → 3.0.02014-04-01

3.1.3 → 4.0.02016-04-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/f0031d3ec8ff8b09844a9e31ee1569f4430c7972983fdf06839abd35764b3e51?d=identicon)[SamsonIT](/maintainers/SamsonIT)

---

Top Contributors

[![Burgov](https://avatars.githubusercontent.com/u/417674?v=4)](https://github.com/Burgov "Burgov (6 commits)")[![SamsonIT-Jelle](https://avatars.githubusercontent.com/u/47599676?v=4)](https://github.com/SamsonIT-Jelle "SamsonIT-Jelle (4 commits)")[![dsuurlant](https://avatars.githubusercontent.com/u/4609379?v=4)](https://github.com/dsuurlant "dsuurlant (1 commits)")[![ErikTrapman](https://avatars.githubusercontent.com/u/1147578?v=4)](https://github.com/ErikTrapman "ErikTrapman (1 commits)")[![knalblauw](https://avatars.githubusercontent.com/u/4919242?v=4)](https://github.com/knalblauw "knalblauw (1 commits)")[![SchizoDuckie](https://avatars.githubusercontent.com/u/111710?v=4)](https://github.com/SchizoDuckie "SchizoDuckie (1 commits)")

### Embed Badge

![Health badge](/badges/samson-filter-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/samson-filter-bundle/health.svg)](https://phpackages.com/packages/samson-filter-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M388](/packages/easycorp-easyadmin-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[kimai/kimai

Kimai - Time Tracking

4.8k9.0k1](/packages/kimai-kimai)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
