我找不到任何有用的东西。我正在尝试创建 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'));
蛋糕返回这个:
404 缺少 Recepies::api_1()
这是我通过的CakePHP文档
此外,非常感谢有关正确 RESTful API 设计的任何其他建议!:)