jacoz / doctrine-query-builder-from-request
该包已被弃用且不再维护。未建议替代包。
将请求转换为 doctrine 查询
dev-master
2018-01-29 11:21 UTC
Requires
- php: >=5.4.0
- doctrine/orm: ~2.2,>=2.2.3
- symfony/http-foundation: ~2.6
Requires (Dev)
- phpunit/phpunit: ~4.7
This package is not auto-updated.
Last update: 2018-12-29 20:43:24 UTC
README
一个方便的查询系统 :)
需求
- PHP >= 5.4
- Symfony HTTP Foundation > 2.6
- Doctrine ORM > 2.2.3
安装
使用 Composer
{
"require": {
"jacoz/doctrine-query-builder-from-request": "dev-master"
}
}
参数
| 参数 | 类型 | 有效值 | 描述 | 默认值 |
|---|---|---|---|---|
count |
布尔值 |
true, false |
指定查询是否返回元素数量或记录集 | false |
select |
数组 |
- | 要选择字段列表 | * |
params |
对象 |
- | 搜索参数键值对象 | {} |
boolStrategy |
字符串 |
AND, OR |
指定默认布尔策略 | AND |
joins |
对象 |
- | 关系和别名键值对象 | null |
sorting |
对象 |
- | 字段和方向的键值对象 | null |
limit |
整数 |
数字 | 最大结果数 | null |
offset |
整数 |
数字 | 起始偏移量 | null |
用法
您的控制器可能是这样的
<?php namespace Acme\MainBundle\Controller; use Jacoz\Doctrine\ORM\QueryBuilderFromRequest\QueryBuilder; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; class DefaultController extends Controller { public function indexAction(Request $request) { $repository = $this->getDoctrine()->getManager()->getRepository('AcmeMainBundle:Person'); $qb = new QueryBuilder($repository, $request); $results = $qb->getResult(); return new JsonResponse($results); } }
查询示例
{
"boolStrategy": "OR",
"count": false,
"select": [
"id",
"name",
["c.name", "city"]
],
"params": {
"c.id": [
1,
2
],
"height": "> 175",
"birthday": {
"type": "date",
"from": "1980-01-01",
"to": "1989-12-31"
},
"salary": {
"type": "numeric",
"from": 50000,
"to": 70000
},
"x": {
"type": "instance_of",
"class": "Acme\\DemoBundle\\Entity\\Employee"
}
},
"joins": {
"city": "c"
},
"sorting": {
"c.name": "ASC",
"name": "ASC"
},
"limit": 100,
"offset": 0
}