简体   繁体   中英

routes.php and controllers (codeigniter)

I have two controllers 1- site 2- management

the first controllers(Site) is work successfuly the second controllers(Managemnt) is not work.

I don't know what is the errror

I change the routes.php but still doesn't work(managment)

$route['default_controller'] = "site";
$route['(:any)'] = "site/$1";
$route['Administration'] = "Administration/index";
$route['Administration/([a-z])'] = 'Administration/$1';

this links work:

example.com/hotel/12312

example.com/contact

example.com/city/newyork

example.com/Administration

but this links doesn't works:

example.com/Administration/hotels

example.com/Administration/add_new

example.com/Administration/cities

where is the problem pls because I tired to solve this problem

thaks

It has to do with the order in witch you are giving route directives. Code igniter routes requests from top to bottom, so if you want your $route['Administration'] to precede $route['(:any)'] you have to set it first.

 $route['default_controller'] = "site"; $route['Administration/([az])'] = 'Administration/$1'; $route['Administration'] = "Administration/index"; $route['(:any)'] = "site/$1"; 

I would allways sugest putting (:any) routes at the end so they don't overwrite more specific routes.

I had same problem & I get this working:

$route['default_controller'] = "welcome";
$route['([a-z-A-Z1-9_]+)'] = "site";
$route['management']="management";
$route['404_override'] = '';

it may help you!

I'm not familiar with Codeigniter routing, but to me looks like everything is matching $route['(:any)'] = "site/$1"; before it ever reaches your Administration routes. Try moving it below everything else...you might also have to switch your Administration routes for the ([az]) to match

$route['default_controller'] = "site";
$route['Administration/([a-z])'] = 'Administration/$1';
$route['Administration'] = "Administration/index";
$route['(:any)'] = "site/$1";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM