简体   繁体   中英

using subfolders in codeigniter causes problems

I am getting page not found error in my CI web app I have 3 seperate sub-folders with controllers inside of them, admin, site, members. the structure looks like so.

- Controllers
--- Site
----- site.php <-- handles all general site pages
--- Members
----- dashboard.php <-- default controller to be called when no parameter is passed
----- products.php <-- handles all products request
--- Admin
---- dashboard.php <-- default controller to be called when no parameter is passed
---- members.php <-- handles all members request

I tried routing it in the routes.php file like this

// Admin - folder/controler/Method

$route['admin/(:any)'] = 'admin/admin/$1';
$route['admin'] = 'admin/dashboard/index'; 

$route['clients/(:any)'] = 'clients/$1';
$route['clients'] = 'clients/dashboard/index';

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

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

What do I do to fix this?

Please try

// Admin - folder/controler/Method

$route['default_controller'] = 'site';
$route['404_override'] = '';

$route['admin/(:any)'] = 'admin/admin/$1';
$route['admin'] = 'admin/dashboard'; 


$route['clients/(:any)'] = 'clients/$1';
$route['clients'] = 'clients/dashboard';



$route['(:any)'] = 'site/$1';
  • get rid of method ( index )
  • different order
  • let reserved routes on top

Order of routes is important, when CI finds the first valid route it won't do the other routes in the list.

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