Yousuf Memon
Yousuf Memon

Reputation: 4798

CodeIgniter: Understanding routes

I have the this route defined in routes.php $route['user'] = "user_controller";. The user controller has a method logout() but when I try this URI user/logout I get a 404. In the same way when I use this URI user/index I get a 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'] = '';

Upvotes: 0

Views: 258

Answers (2)

Linar Garifullin
Linar Garifullin

Reputation: 24

Yep, you have to specify a route for each particular method.

Here's an example from my routes.php :

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

Upvotes: 0

tomexsans
tomexsans

Reputation: 4527

According to CI

Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.

$route['default_controller'] and $route['404_override'] must always be on top above others

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

Example i will type a user/logout then it will proceed to user_controller/logout you have to define the URL you would like to redirect

Upvotes: 1

Related Questions