我有一个与数据库连接的rest
服务,到目前为止我只设法从数据库
获取完整集合或通过其ID获取单个实体
.
我找不到合适的指南来解释如何使用 GET
url 参数按其他字段进行过滤,以及如何选择,例如是“LIKE”还是“LIKE %%”或其他运营商。
最佳答案
这是我使用 CodeConnected Services 的经验。 YMMV..
检索 URL 参数 - Controller /资源类。
您的 Controller 需要从 $this->getEvent()
检索它们
/**
* Fetch a single Entity by ID, with some Query Params
*/
public function fetch($entity_id)
{
// retrieve the query parameters\
$queryParams = $this->getEvent()->getQueryParams();
}
其次,只有在 module.config.php 上批准的参数才能通过 Apigility 的验证器/过滤器部分。通知集合查询白名单
module.config.php
在服务的模块文件夹中
'ServiceName\\V1\\Rest\\ServiceName\\Controller' => array(
...
'entity_http_methods' => array(
0 => 'GET',
1 => 'PATCH',
2 => 'PUT',
3 => 'DELETE',
),
'collection_http_methods' => array(
0 => 'GET',
1 => 'POST',
),
'collection_query_whitelist' => array(
0 => 'username',
1 => 'entity_provider',
2 => 'entity_type',
3 => 'entity_date_range',
4 => 'sort_by',
5 => 'sort_order'
),
...
关于php - Apigility Rest 服务 - 如何使用连接的数据库按非唯一列进行过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26572191/