代码之家  ›  专栏  ›  技术社区  ›  sdot257

Codeigniter-类似Twitter的URI路由

  •  1
  • sdot257  · 技术社区  · 14 年前

    http://www.domain.com/profile/jimbob123

    $route['profile'] = "profile/index";
    $route['profile/(:any)'] = "profile/index/$1";
    

    现在,假设我希望我的URL在显示“状态”时如下所示

    http://www.domain.com/profile/jimbob123/status/908734efc

    如何将“jimbob123”和“908734efc”传递到我的方法中,以便检查和检索此特定记录?我试过以下方法,但似乎不起作用。

    $route['user/(:any)/status/(:any)'] = "user/plan/$1/$2";
    
    1 回复  |  直到 14 年前
        1
  •  3
  •   Ken Struys    14 年前

    我猜你是在哪里写的 user/(:any)/status/(:any) 你是说 profile/(:any)/status/(:any)

    这可能是一个问题,还有:

    路由按照声明的顺序进行匹配。如果你这样写:

    $route['profile'] = "profile/index";
    $route['profile/(:any)'] = "profile/index/$1";
    $route['profile/(:any)/status/(:any)'] = "user/plan/$1/$2";
    

    如果你换了第二和第三行,你应该做得很好。

    $route['profile'] = "profile/index";
    $route['profile/(:any)/status/(:any)'] = "user/plan/$1/$2";
    $route['profile/(:any)'] = "profile/index/$1";