2014-05-13 36 views
0
$route['default_controller'] = "index"; 

$route['404_override'] = ''; 

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

$route['admin'] = "admin/index"; 

$route['admin/add_category'] = "admin/index/add_category"; 

作品:笨路線的子文件夾不工作

$route['admin/edit_category/2'] = "admin/index/edit_category/2"; 

不工作:

$route['admin/edit_category/(:any)'] = "admin/index/edit_category/$1"; 
+0

可能重複[笨路線(http://stackoverflow.com/questions/7070500/codeigniter-routes) – Chococroc

回答

0

儘量把你的路由規則之前,這一切都捕捉

$route['admin'] = "admin/index"; // no params at first 

$route['admin/add_category'] = "admin/index/add_category"; // extend first rule 

$route['admin/edit_category/(:any)'] = "admin/index/edit_category/$1"; // and one more 

$route['default_controller'] = "index"; // default settings 

$route['404_override'] = ''; 

$route['(:any)'] = 'index/$1'; // ok, now we can brake MVC pattern, but should we? 

例如我的路由文件中的一個(作品肯定):

$route['project-admin/login'] = "project-cms/user/index"; 
$route['project-admin/recovery'] = "project-cms/user/recovery"; 
$route['project-admin'] = "project-cms/admin/index"; 
$route['project-admin/(:any)'] = "project-cms/admin/$1"; 
$route['project-admin/(:any)/(:any)'] = "project-cms/admin/$1/$2";