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/";
$route['auth'] = "bit_auth";

我使用时工作正常:http://(mydomain.com)/auth/
但是 打开链接时显示 404 找不到页面错误,例如:
http://(mydomain.com)/auth/edit_user/1
http://(mydomain.com)/auth/activate/7b60a33408a9611d78ade9b3fba6efd4fa9eb0a9

我做错了什么?

因为你使用的参数比路由中的多,所以你必须这样做:

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

希望对您有所帮助!

在谷歌搜索和调查之后,我看到他们在某个地方使用另一种语法在 CodeIgniter 中直接使用 regular expression 进行路由而不是在其帮助中使用 codeigniter 描述的模式,如 (:any)(:num)。我刚刚在我的 config/routes.php 中用 (.+) 替换了 (:any) 现在它运行完美了。

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

因为在 CodeIgniter 中 (:any)(:num) 不包括 / 并且它们是 [=19= 的正则表达式模式的别名] 和 (\d+) 所以如果你想匹配其余的 link 包括任意数量的 / 你可以使用手动正则表达式模式 (.+) 其中包括 /它的模式并将触发 URL.

的所有其余部分