php - Apigility Rest 服务 - 如何使用连接的数据库按非唯一列进行过滤

标签 php rest zend-framework2 laminas-api-tools

我有一个与数据库连接的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/

相关文章:

javascript - 数据库中的 JQuery 自动完成

rest - 上传 base64 编码的图像是一种不好的做法吗?

java - 如何使用 spring boot 压缩下载的文件

json - Grails RESTful Controller 。 POST 命中 index() 而不是 save()

zend-framework2 - zend 2 : Unable to render template . .. 解析器无法解析到文件

php - 需要使用什么 sniff 来强制执行驼峰式变量命名约定?

php - 执行创建 "MySQL server has gone away"错误

PHP 不区分大小写和重音搜索数组

mysql - 如何在 zend framework2 的 mysql 查询中使用 YEAR(date)

php - ZF2 中的 CORS POST 请求变为 OPTIONS 请求