CakePHP 2.0路由器::连接如何传递命名参数

CakePHP 2.0路由器::连接如何传递命名参数,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我正在CakePHP2.0中重建一个站点,需要将一些旧URL路由到新URL。例如,这: 将路由到此: 为了做到这一点,我有以下路线: Router::connect( '/widget/helpbox/location/mackay-qld', array( 'controller' => 'widgets', 'action' => 'answer', 'location_id' => 10542 )

我正在CakePHP2.0中重建一个站点,需要将一些旧URL路由到新URL。例如,这:

将路由到此:

为了做到这一点,我有以下路线:

Router::connect(
    '/widget/helpbox/location/mackay-qld',
    array(
        'controller' => 'widgets',
        'action' => 'answer',
        'location_id' => 10542
    )
);
当我调试$this->request->params时,我得到以下结果:

Array
(
    [plugin] => 
    [controller] => widgets
    [action] => answer
    [named] => Array
        (
        )

    [pass] => Array
        (
        )

    [location_id] => 10542
    [isAjax] => 
)
但我预计:

Array
(
    [plugin] => 
    [controller] => widgets
    [action] => answer
    [named] => Array
        (
            [location_id] => 10542
        )

    [pass] => Array
        (
        )

    [isAjax] => 
)
我也试过打电话

Router::connectNamed(array('location_id'));
…但没有用。位置_id仍然以相同的方式传递-不是作为命名参数传递


有人知道正确的语法吗?

在提交了一张罚单并得到了无效罚单的回复后,这迫使我进一步挖掘。我终于明白需要做什么了。由于入站URL不包含命名参数,因此无法按您尝试的方式进行路由连接。路由连接用作如何将某些位置路由到新位置的模板。但是,您要做的是将特定URL路由到新URL。您正在寻找的是重定向

Router::redirect(
    '/widget/helpbox/location/mackay-qld',
    array(
        'controller' => 'widgets',
        'action' => 'answer',
        'location_id' => 10542,
    ),
);

这将返回您正在查找的结果。

这可能是一个错误。考虑向CAKE2家伙提问/报告。很高兴听到这个消息!Mark Story将我的bug设置为无效,从而使我走上了正确的道路。哈哈。但我很高兴它对你有用。