Cakephp重新路由

时间:2013-11-28 02:01:04

标签: cakephp url-rewriting routes

嗨我喜欢能够重写我的网址。我有这种格式的网址:

localhost/example/urlrewriting/Links/view/1

我想将此网址更改为

http://localhost/example/urlrewriting/tt/my-link-1

在我的Routes.php中,我做到了这一点:

    Router::connect('tt/:slug-:id',
    array('controller' =>'links', 'action' => 'test'),
    array('pass' => array('slug', 'id'), 'slug' => '[a-z0-9\-]+', 'id' => '[0-9]+'));

在我的控制器中我有这个

    public function test($param1, $param2){
    debug($this->request->params);
}

我总能找到答案:

TtController could not be found.

cakephp 2.4.1

1 个答案:

答案 0 :(得分:3)

请在连接参数之前添加/,如: -

Router::connect('/tt/:slug-:id',
array('controller' =>'links', 'action' => 'test'),
array('pass' => array('slug', 'id'), 'slug' => '[a-z0-9\-]+', 'id' => '[0-9]+'));