CodeIgniter:了解路线

时间:2013-02-08 03:24:20

标签: codeigniter routes

我在 routes.php 中定义了此路线 $route['user'] = "user_controller";。用户控制器有一个方法logout()但是当我尝试这个URI user/logout时,我得到了404.就像我使用这个URI user/index时一样,我得到了一个404.

routes.php文件

// custom routes
$route['start'] = "start_controller";
$route['register'] = "register_controller";
$route['user'] = "user_controller";

// other routes
$route['default_controller'] = "start_controller";
$route['404_override'] = '';

2 个答案:

答案 0 :(得分:1)

根据CI

  

注意:路由将按照定义的顺序运行。更高的路线   将始终优先于较低的。

$route['default_controller']$route['404_override']必须始终位于其他人之上

$route['user/logout'] = "user_controller/logout";
$route['user/index'] = "user_controller";

示例我将输入user/logout然后它将继续user_controller/logout您必须定义要重定向的URL

答案 1 :(得分:0)

是的,您必须为每种特定方法指定路线。

这是我的routes.php中的一个例子:

/* User Authentication Controller */
$route['login']     = "auth/login";
$route['logout']    = "auth/logout";
$route['register']  = "auth/register";
$route['forgot']    = "auth/forgot";