【问题标题】:Cakephp reroutingCakephp 重新路由
【发布时间】:2013-12-13 22:04:37
【问题描述】:

您好,我希望能够重写我的网址。我有这种格式的网址:

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

【问题讨论】:

    标签: cakephp url-rewriting routes


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2022-10-05
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 2011-04-17
      • 1970-01-01
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      相关资源
      最近更新 更多