0

可能重复:
CodeIgniter - 使用 $route['(:any)'] = 'pages/view/$1' 时如何使用其他控制器?

我正在使用 codeigniter 中的 url 缩短器/重定向 Web 应用程序,但我的路线遇到了问题。

我的第一条路线是:

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

这是处理重定向的内容,因此 example.com/dwB 将转到重定向控制器。

在下面,我有一些路由覆盖了页面和其他控制器等。当我描述包括参数等在内的整个 url 时,它们工作正常,但我现在遇到了麻烦,因为我有一些动态 url,例如:

 example.com/stats/view/dwB

或 facebook auth 响应等,我显然无法为其编写路线。我试过使用类似的东西:

 $route['stats/view/(:any)'] = "stats/view/$1";

但这些似乎都没有覆盖第一条路线。这是我的整个 routes.php 文件。

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

$route['shorten/create'] = "shorten/create"; // overwrite the previous route

$route['stats/view/(:any)'] = "stats/view/$1"; // allow the stats controller to be used

$route['login'] = "auth/login"; // allow the login(auth) controller to be used
$route['register'] = "auth/register"; // allow the login(auth) controller to be used
$route['auth_social/fblogin'] = "auth_social/fblogin"; // allow the login(auth) controller    to be used
$route['dashboard'] = "dashboard"; // allow the login(auth) controller to be used
$route['auth/logout'] = "auth/logout"; // allow the login(auth) controller to be used
$route['auth'] = "auth/index"; // allow the login(auth) controller to be used

$route['default_controller'] = "pages";

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

1 回答 1

2

正如我在评论中提到的,将您的“任何”路由放在自定义路由的末尾,如下所示:

$route['shorten/create'] = "shorten/create"; // overwrite the previous route

$route['stats/view/(:any)'] = "stats/view/$1"; // allow the stats controller to be used

$route['login'] = "auth/login"; // allow the login(auth) controller to be used
$route['register'] = "auth/register"; // allow the login(auth) controller to be used
$route['auth_social/fblogin'] = "auth_social/fblogin"; // allow the login(auth) controller    to be used
$route['dashboard'] = "dashboard"; // allow the login(auth) controller to be used
$route['auth/logout'] = "auth/logout"; // allow the login(auth) controller to be used
$route['auth'] = "auth/index"; // allow the login(auth) controller to be used

// Move "any" route down here...
$route['(:any)'] = "redirect/index/$1";
于 2013-01-01T18:28:05.643 回答