Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readme, two steps to use #26

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,61 @@ The bundle can be installed using Composer or the [Symfony binary](https://symfo
composer require spiriitlabs/form-filter-bundle
```

## Use it in two steps

### create a form

```php
<?php
namespace Project\Form\Filter;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
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);
}
}
```

### use it in your controller

```php
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,
]);
}
}
```

Documentation
=============

Expand Down
Loading