swaroge / simple-text-filter-bundle
Simple text filter bundle
Installs: 36
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
This package is not auto-updated.
Last update: 2025-09-09 12:33:21 UTC
README
Its simple filter for Symfony 2 Entity.
Installation
composer
- "require" section
"require": { "swaroge/simple-text-filter-bundle" : "dev-master" }
- "repositories" section
"repositories" : [{ "type" : "vcs", "url" : "https://github.com/swaroge/SimpleTextFilterBundle.git" }],
$ composer update
- add service in services.yml
$ composer update
Usage
- Create FormType for filter
- Create jsonSerializeFilter metod in Entity
- Changes in controller
- Twig example
Create FormType
create new form type for filter form:
<?php
namespace My\TestBundle\Form;
/* ... */
class TestFormType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
;
}
}
/* ... */
/**
* @return string
*/
public function getName()
{
return 'my_testbundle_filter';
}
}
Create jsonSerializeFilter metod in Entity
dont forgott
<?php
class EntityName implements \JsonSerializable
create public method in class
<?php
public function jsonSerializeFilter() {
/* fields used in form */
return [
'name'=>$this->getAddress(),
];
}
Changes in controller
<?php
/*...*/
public function indexAction(){
$textSimpleFilter = new TextSimpleFilter();
$form_filter = $this->get('form.factory')->create(new TestFilterType());
$form_filter->handleRequest($this->get('request'));
}
$query = $textSimpleFilter->queryFilter($query,$form_filter->getData(),get_class(new Product()));