3

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

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 page not found 错误:
http://(mydomain.com)/auth/edit_user/1
http ://(mydomain.com)/auth/activate/7b60a33408a9611d78ade9b3fba6efd4fa9eb0a9

我究竟做错了什么?

4

2 回答 2

4

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

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

希望这可以帮助!

于 2015-05-20T15:34:02.680 回答
1

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

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

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

于 2015-05-22T10:24:56.087 回答