正在構建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