定制 spiriitlabs/form-filter-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spiriitlabs/form-filter-bundle

Composer 安装命令:

composer require spiriitlabs/form-filter-bundle

包简介

Symfony bundle for dynamic filtering, search forms and Doctrine query generation

README 文档

README

The LexikFormFilterBundle, a historical bundle, is now renamed to SpiriitFormFilterBundle. The code remains unchanged; only the name and organization have changed on GitHub.

This Symfony bundle aims to provide classes to build some form types dedicated to filter an entity. Once you created your form type you will be able to update a doctrine query builder conditions from a form type.

PHP Version Packagist Downloads Latest Stable Version CI Tests

The idea is:

  1. Create a form type extending from Symfony\Component\Form\AbstractType as usual.
  2. Add form fields by using provided filter types (e.g. use TextFilterType::class instead of a TextType::class type) (*).
  3. Then call a service to build the query from the form instance and execute your query to get your result :).

(*): In fact you can use any type, but if you want to apply a filter by not using a XxxFilterType::class type you will have to create a custom listener class to apply the filter for this type.

Installation

================

The bundle can be installed using Composer or the Symfony binary:

composer require spiriitlabs/form-filter-bundle

Use it in two steps

create a form

<?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

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

This Symfony bundle is compatible with Symfony 4.3 or higher.

For Symfony 2.8/3.4 please use tags v5.*

For installation and how to use the bundle refer to Resources/doc/index.md

  1. Installation
  2. Configuration
  3. Provided form types
  4. Example & inner workings
    1. Simple example
    2. Inner workings
  5. Working with the filters
    1. Customize condition operator
    2. Filter customization
    3. Working with entity associations and embeddeding filters
    4. Doctrine embeddables
    5. Create your own filter type
    6. Enable validation on your filter type
  6. The FilterTypeExtension
  7. Working with other bundles
    1. KNP Paginator example
  8. Real use case - Advanced usage with PagerFanta

Community Support

Please consider opening a question on StackOverflow using the spiriitformfilterbundle tag, it is the official support platform for this bundle.

Github Issues are dedicated to bug reports and feature requests.

For compatibility with Symfony 2.8 and 3.4

Please use last tag v5.*

Credits

License

This bundle is under the MIT license.
For the whole copyright, see the LICENSE file distributed with this source code.

spiriitlabs/form-filter-bundle 适用场景与选型建议

spiriitlabs/form-filter-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 535.13k 次下载、GitHub Stars 达 39, 最近一次更新时间为 2023 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「form」 「bundle」 「doctrine」 「filter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 spiriitlabs/form-filter-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 spiriitlabs/form-filter-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 spiriitlabs/form-filter-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 535.13k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 39
  • 点击次数: 18
  • 依赖项目数: 7
  • 推荐数: 2

GitHub 信息

  • Stars: 39
  • Watchers: 4
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-14