Cakephp插件的RESTful路由

时间:2015-10-20 16:16:38

标签: php rest cakephp

我在Cakephp应用程序中配置Restful路由到自定义插件时遇到一些问题。根据所执行的休息操作的类型,不会将路线指向适当的行动。

routes.php中的代码

Router::resourceMap( array(
    array( 'action' => 'index', 'method' => 'GET', 'id' => false ),
    array( 'action' => 'view', 'method' => 'GET', 'id' => true ),
    array( 'action' => 'add', 'method' => 'POST', 'id' => false),
    array( 'action' => 'edit', 'method' => 'PUT', 'id' => true ),
    array( 'action' => 'delete', 'method' => 'DELETE', 'id' => true ),
) );
Router::mapResources('chronos.chronosApplications'); // chronos is plugin name and chronosApplications is controller in this plugin

我正在使用的请求网址是/ chronos / chronosApplications / 1,请求类型为delete。

错误日志

2015-10-20 16:14:23 Error: [MissingActionException] Action ChronosApplicationsController::40() could not be found.
Exception Attributes: array (
  'controller' => 'ChronosApplicationsController',
  'action' => '40',
)
Request URL: /chronos/chronosApplications/40
Stack Trace:
#0 /usr/share/pear/Cake/Routing/Dispatcher.php(185): Controller->invokeAction(Object(CakeRequest))
#1 /usr/share/pear/Cake/Routing/Dispatcher.php(160): Dispatcher->_invoke(Object(ChronosApplicationsController), Object(CakeRequest), Object(CakeResponse))
#2 /var/www/prime/desman/webroot/index.php(110): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#3 {main}

谢谢。

1 个答案:

答案 0 :(得分:0)

首先是它的" mapResources",但要定义你使用的路线"路由器::连接('链接','动作',& #39; OBS');"

http://book.cakephp.org/2.0/en/development/routing.html#connecting-routes

中详细了解相关信息