petkopara/multi-search-bundle
Composer 安装命令:
composer require petkopara/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 petkopara/multi-search-bundle
Add it to the AppKernel.php class:
new Petkopara\MultiSearchBundle\PetkoparaMultiSearchBundle(),
##Usage
Service
You can directly use the service and to apply the multi search to any doctrine query builder.
public function indexAction(Request $request)
{
$search = $request->get('search');
$em = $this->getDoctrine()->getManager();
$qb = $em->getRepository('AppBundle:Post')->createQueryBuilder('e');
$qb = $this->get('petkopara_multi_search.builder')->searchEntity($qb, 'AppBundle:Post', $search);
//$qb = $this->get('petkopara_multi_search.builder')->searchEntity($qb, 'AppBundle:Post', $search, array('name', 'content'), 'wildcard');
..
}
Form
Create your form type and include the multiSearchType in the buildForm function:
use Petkopara\MultiSearchBundle\Form\Type\MultiSearchType;
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('search', MultiSearchType::class, array(
'class' => 'AppBundle:Post', //required
'search_fields' => array( //optional, if it's empty it will search in the all entity columns
'name',
'content'
),
'search_comparison_type' => 'wildcard' //optional, what type of comparison to applied ('wildcard','starts_with', 'ends_with', 'equals')
))
;
}
In the controller add call to the multi search service:
public function indexAction(Request $request)
{
$search = $request->get('search');
$em = $this->getDoctrine()->getManager();
$queryBuilder = $em->getRepository('AppBundle:Post')->createQueryBuilder('e');
$filterForm = $this->createForm('AppBundle\Form\PostFilterType');
// Bind values from the request
$filterForm->handleRequest($request);
if ($filterForm->isValid()) {
// Build the query from the given form object
$queryBuilder = $this->get('petkopara_multi_search.builder')->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 withequalsif 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
Petko Petkov - petkopara@gmail.com
License
MultiSearchBundle is licensed under the MIT License.
petkopara/multi-search-bundle 适用场景与选型建议
petkopara/multi-search-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66.4k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2016 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「doctrine」 「query-builder」 「symfony3」 「multi-search」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 petkopara/multi-search-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 petkopara/multi-search-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 petkopara/multi-search-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony 2 & 3 JSON API Transformer Package
A Symfony bundle for v3 of the AWS SDK for PHP
Integrates php-amqplib with Symfony & RabbitMq. Formerly oldsound/rabbitmq-bundle.
Laravel, Lumen and Native php elasticseach query builder to build complex queries using an elegant syntax
A Symfony 2-3 bundle to manage Resque job queues
The Authentication Bundle
统计信息
- 总下载量: 66.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 17
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-24