承接 sgloe/multi-search-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

sgloe/multi-search-bundle

最新稳定版本:v0.0.6

Composer 安装命令:

composer require sgloe/multi-search-bundle

包简介

Symfony bundle for Multi Criteria Search for doctrine entities using Form or Service.

README 文档

README

This bundle provides basic service and form type for Multi Search in Doctrine.

Description

Search in all of entity columns by given search term. In response returns Doctrine\ORM\QueryBuilder containing the multiple search criteria. The searched columns can be specified.

Installation

Using composer

composer require sgloe/multi-search-bundle

Add it to your config/bundles.php:

Sgloe\MultiSearchBundle\SgloeMultiSearchBundle::class => ['all' => true],

Usage

Service

You can inject the service and apply the multi search to any Doctrine query builder.

use Sgloe\MultiSearchBundle\Service\MultiSearchBuilderService;

public function __construct(
    private MultiSearchBuilderService $multiSearchBuilder,
    private EntityManagerInterface $entityManager,
) {}

public function index(Request $request): Response
{
    $search = $request->query->get('search');

    $qb = $this->entityManager->getRepository(Post::class)->createQueryBuilder('e');
    $qb = $this->multiSearchBuilder->searchEntity($qb, Post::class, $search);
    //$qb = $this->multiSearchBuilder->searchEntity($qb, Post::class, $search, ['name', 'content'], 'wildcard');

    ..
}

Form

Create your form type and include the multiSearchType in the buildForm function:

use Sgloe\MultiSearchBundle\Form\Type\MultiSearchType;

public function buildForm(FormBuilderInterface $builder, array $options): void
{
    $builder
        ->add('search', MultiSearchType::class, [
            'class' => Post::class, //required
            'search_fields' => [ //optional, if it's empty it will search in all entity columns
                'name',
                'content',
            ],
            'search_comparison_type' => 'wildcard', //optional, what type of comparison to apply ('wildcard','starts_with', 'ends_with', 'equals')
        ])
    ;
}

In the controller, inject the service and call the multi search:

use Sgloe\MultiSearchBundle\Service\MultiSearchBuilderService;

public function __construct(
    private MultiSearchBuilderService $multiSearchBuilder,
    private EntityManagerInterface $entityManager,
) {}

public function index(Request $request): Response
{
    $queryBuilder = $this->entityManager->getRepository(Post::class)->createQueryBuilder('e');
    $filterForm = $this->createForm(PostFilterType::class);

    // Bind values from the request
    $filterForm->handleRequest($request);

    if ($filterForm->isSubmitted() && $filterForm->isValid()) {
        // Build the query from the given form object
        $queryBuilder = $this->multiSearchBuilder->searchForm($queryBuilder, $filterForm->get('search'));
    }

    ..
}

Render your form in the view

{{ form_rest(filterForm) }}

Available Options

The provided type has 2 options:

  • search_fields - array of the entity columns that will be added in the search. If it's not set then will search in all columns

  • search_comparison_type - how to compare the search term.

    • wildcard - it's equivalent to the %search% like search.

    • equals - like operator without wildcards. Wildcards still can be used with equals if the search term contains *.

    • starts_with - it's equivalent to the %search like search.

    • ends_with - it's equivalent to the search% like search.

These parameters can be applyed to the service as well as 4th and 5th parameter to searchEntity() method

Author

Sgloe

Thanks to Petko Petkov, who originally wrote this bundle. Since it is not maintained anymore, I started this fork.

License

MultiSearchBundle is licensed under the MIT License.

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固