正在构建API并希望使用RESTful routes。在CakePHP中使用具有RESTful路由的路由前缀
我得到它的工作只是罚款是这样的:
http://www.mysite.com/events.json // returns json results with my events
http://www.mysite.com/events/123.json // returns json results with event of id '123'
但是 - 我希望能够做到这一点使用“API”前缀。
所以,我加入了API路由前缀:
Configure::write('Routing.prefixes', array('admin', 'api'));
而且从 '视图' 和 '指标' 到 'api_view' 和 'api_index' 改变了我的行动。
但现在它不起作用。 (例如:我有写操作名称,否则将无法找到基于HTTP正确的
的最终目标将是能够做这样的事情:
GET http://www.mysite.com/api/1.0/events.json // loads events/api_index()
GET http://www.mysite.com/api/1.0/events/123.json // loads events/api_view($id)
DELETE http://www.mysite.com/api/1.0/events/123.json // loads events/api_delete($id)
...etc
我可以很好地管理路由器 - 这个问题还允许REST根据HTTP类型确定它是否应该显示“视图”或“索引”等。 – Dave
声明路由并在第二个参数数组中使用[method]。像这里显示http://book.cakephp.org/2.0/en/development/routing.html#using-additional-conditions-when-matching-routes另见https://github.com/kvz/cakephp-rest-插件 – burzum
我想我明白了 - 将在早上尝试。谢谢。 – Dave