比方說,我有一個名爲控制器如何設置動態路由在CodeIgniter中使用slug?
,有一個方法
slug_on_the_fly
public function slug_on_the_fly($slug)
頁如何將我這個樣子路線?
E.g.對於博客控制器就會很容易:
$route['blog/(:any)'] = 'pages/slug_on_the_fly/$1';
然後http://localhost/blog/name-of-the-article
工作良好
但是,如果我想要做什麼,它就像一個沒有blog
所以如
http://localhost/name-of-the-article
或http://localhost/another-article-blablabla
如何做到這一點,不破例如另一路線$route['friends'] = 'users';
或$route['about-us'] = 'pages/about_us';
?
因爲如果我這樣做: $route['(:any)'] = 'pages/slug_on_the_fly/$1';
這可能會毀掉一切還是?
任何想法如何路由這種情況? – Derfder 2013-03-12 17:00:15
將「catch-all」路由放到最後,並確保該方法使用'error_404()',如果它找不到任何東西。 – 2013-03-12 17:16:06
你能更具體嗎?如果我把'$ route ['(:any)'] ='pages/slug_on_the_fly/$ 1';'最後所有的東西都會被擰緊 – Derfder 2013-03-12 17:50:11