CakePHP 2.3中的路由

问题描述 投票:1回答:1

我对CakePHP 2.x Custom Route with Arguments提出了类似的问题,我希望将该参数用作我的变量之一。

(域/ PARAM /控制器/动作/ PARAM)

Router::connect(
    '/:sitecode/:controller/:action/*',
    array(),
    array('sitecode' => '[A-Z]{20}', 'persist' => array('sitecode'))
);

上面的代码不起作用,它仍然将:sitecode视为控制器,并将:controller视为动作。我做错了什么?

我以后如何从我的代码访问:sitecode

cakephp-2.3
1个回答
2
投票
Customize your route like this:

Router::connect(
   '/:sitecode/:controller/:action/*',
   array('controller' => :controller, 'action' => :action),
   array('sitecode' => '[A-Z]{20}', pass => ['sitecode'])
);
Later in your code get sitecode using - $this->request->params['sitecode']
© www.soinside.com 2019 - 2024. All rights reserved.