這實際上與MVC無關,還有更多關於良好URL的內容。
你要找的是雙方的URL(一)但從用戶的角度和明確的(b)該給的提示,你的應用程序,以它是如何打算處理。
我會做什麼在這種情況下略微重新設計你的URL,這樣,而不是:
http://www.groupon.com/las-vegas/
http://www.groupon.com/orlando/
你將不得不網址看起來像這樣:
http://www.groupon.com/destinations/las-vegas/
http://www.groupon.com/destinations/orlando/
位開頭 - /destinations/
- 可以被你的URL路由代碼用來決定哪個控制器應該處理它。如果您的路由代碼是基於URL的,你可能有一個這樣的數組:
$routes = array(
'/destinations/' => 'on_destination_list',
'/destinations/(.+)' => 'on_destination',
'/(.*)' => 'on_page');
// Basic URI routing code based off of REQUEST_URI
foreach ($pattern => $func) {
if (preg_match("`^$pattern$`", $_SERVER['REQUEST_URI'], $placeholders)) {
array_shift($placeholders);
call_user_func($func, $placeholders);
}
}
請記住,我寫的路由代碼了我的頭頂部,它可能不完全正確的。它應該給你你需要做的事情的要點。
這樣做,讓有額外的好處,如果有人去http://www.groupon.com/destinations/
,你將有機會展示目的地的列表。
重新映射我應該看的地方? http://codeigniter.com/user_guide/general/controllers.html#remapping – 2011-03-17 22:08:53