doujiu1447 2014-01-10 19:48
浏览 50

用于RESTful-API中的动态DQL的Symfony2-Bundle

I built a simple API in symfony2 with doctrine 2 (with a little help from here: http://williamdurand.fr/2012/08/02/rest-apis-with-symfony2-the-right-way/). Everything works fine. GET (All/One), PUT, POST or DELETE works, but I can either fetch all Resources or only one with a specific Id.

But I want something like this: GET /api/stuff?filter={ [ { "field": "fieldname", "operator": "eq", "value": "foo" }, { ... } ] }

and then call getByFilter($filter) to build a generic DQL. I have a pretty clear idea how to do it (I did something similar, without symfony), but I don't want to reinvent the wheel.

Are there any bundles or best practices out there?

  • 写回答

3条回答 默认 最新

  • douyong6589 2014-01-12 00:42
    关注

    As far as I know, there is no bundle providing generic filtering feature. What you are describing here looks a bit like OData filter system queries, and I never found a bundle implementing such a spec.

    However, the FOSRestBundle provides a ParamFetcher feature, allowing you to configure the query parameters you may expect, as well as default values, and basic validation constraints. This is something to consider while developing the "filtering part" of an API.

    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程