これについて役立つものは何も見つかりません。RESTful ルーティングを作成しようとしています。ルートを次のように表示します。
`GET` routes to `RecipesController::api_index() //instead of RecipesController::index()`
`POST` routes to `RecipesController::api_add() //instead of RecipesController::add()`
`PUT` routes to `RecipesController::api_edit($id) //instead of RecipesController:edit($id)`
`DELETE` routes to `RecipesController::api_delete($id) //instead of RecipesController:delete($id)`
これを行う方法がわかりません。これが私がこれまでに持っているものです:
Router::resourceMap(array(
array('prefix'=>'api', 'action' => 'index', 'method' => 'GET', 'id' => false),
array('prefix'=>'api', 'action' => 'view', 'method' => 'GET', 'id' => true),
array('prefix'=>'api', 'action' => 'add', 'method' => 'POST', 'id' => false),
array('prefix'=>'api', 'action' => 'edit', 'method' => 'PUT', 'id' => true),
array('prefix'=>'api', 'action' => 'delete', 'method' => 'DELETE', 'id' => true),
array('prefix'=>'api', 'action' => 'update', 'method' => 'POST', 'id' => true)
));
Router::mapResources('recipes', array('prefix'=>'api'));
私のcore.php
中で私は次のものを持っています:
Configure::write('Routing.prefixes', array('api'));
Cake はこれを返します:
404 欠落している Recepies::api_1()
ここに私が行くCakePHPのドキュメントがあります
また、適切な RESTful API 設計に関するその他の提案も大歓迎です! :)