繁体   English   中英

CodeIgniter - 如何使用其他名称路由控制器?

[英]CodeIgniter - How to route a controller with other name?

我在codeIgniter中安装了一个名为bit_auth的身份验证模块。 我有一个名为“bit_auth”的模块的控制器,所以在我的控制器上调用函数时,我的URL将是这样的:

http://(mydomain.com)/bit_auth/
http://(mydomain.com)/bit_auth/edit_user/1
http://(mydomain.com)/bit_auth/activate/7b60a33408a9611d78ade9b3fba6efd4fa9eb0a9

现在我想路由我的bit_auth控制器从http://(mydomain.com)/auth/...调用。 我在“ config/routes.php ”中定义了这些路由:

$route['auth/(:any)'] = "bit_auth/$1";
$route['auth'] = "bit_auth";

我使用时工作正常: http://(mydomain.com)/ auth /
它打开链接时显示404页面未找到错误,例如:
HTTP://(mydomain.com)/ AUTH / edit_user / 1
HTTP://(mydomain.com)/ AUTH /激活/ 7b60a33408a9611d78ade9b3fba6efd4fa9eb0a9

我究竟做错了什么?

因为您使用的路径比路线中的更多,所以您必须这样做:

$route['auth/(:any)/(:num)'] = "bit_auth/$1/$2";

希望这可以帮助!

在谷歌搜索和调查后,我看到他们在CodeIgniter中使用另一种语法进行路由的地方直接使用正则表达式而不是在其帮助中使用codeigniter描述的模式(:any)(:any)(:num) 我刚刚在我的config/routes.php中用(.+)替换了(:any) ,现在它工作得很好。

$route['auth/(.+)'] = "bit_auth/$1";
$route['auth'] = "bit_auth";

因为在CodeIgniter (:any)(:num)中不包含/它们是([^\\/]+)(\\d+)正则表达式模式的别名所以如果你想匹配链接的其余部分,包括任何/您可以使用手动正则表达式模式(.+) ,其中包含/在其模式中,并将触发URL的所有其余部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM