PHP code example of samson / filter-bundle

1. Go to this page and download the library: Download samson/filter-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

samson / filter-bundle example snippets


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;
  }
}

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('

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

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