从Codeigniter中的URL中删除控制器功能名称。多个控制器时出错

时间:2015-03-05 11:15:05

标签: php codeigniter url routing config

使用CI如何使用任何方法名称路由到特定控制器。 我有两个控制器:init和cms。然后在config.routes.php中:

 $default_controller = "init";  //default controller
 $controller_exceptions = array('admin','forums');

 $route['default_controller'] = $default_controller;
 $route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
 $route['404_override'] = '';

 $route['backend'] = 'cms';
 $route['backend/(:any)'] = "cms/product";  

当输入后端/产品时,我希望它路由到后端/产品。再次输入后端/登录时,我希望它路由到后端/登录。这意味着我需要的是$route['backend/anyMethodNameAfterbackend'] = "cms/anyMethodNameAfterbackend";

1 个答案:

答案 0 :(得分:1)

而不是$route['backend/(:any)'] = "cms/product";使用$route['cms/(:any)'] = "cms/$1"; 结果将是:

$route['backend'] = 'cms';
$route['backend/(:any)'] = "cms/$1";