2012-11-13 41 views
0

我有立足的形式JSON REST:CakePHP的命名参数打破基于REST的Web服务

Router::mapResources('Test'); 

即相当于为指数法:

Router::connect('/Test', 
       array(
         'controller' => 'ChannelSources', 
         'action' => 'index', 
         '[method]' => 'GET'), 
       array(); 

我想添加对这个方法命名参数的支持。 但显然其断裂路由器方法作为指标动作不是使用 路由器:: connectNamed(阵列(“somenameparam”))的URL

我试图的一部分; 但它失败了。

回答

1

我会创建一个特定的路线,以便您可以传递正确的参数,然后您可以将您的参数传递到路线中。

看一看,http://book.cakephp.org/2.0/en/development/routing.html#passing-parameters-to-action

Router::connect(
    '/blog/:id-:slug', // E.g. /blog/3-CakePHP_Rocks 
    array('controller' => 'blog', 'action' => 'view'), 
    array(
     // order matters since this will simply map ":id" to $articleId in your action 
     'pass' => array('id', 'slug'), 
     'id' => '[0-9]+' 
    ) 
);