How to routes Controller sub folder using codeigni

2019-07-14 20:45发布

问题:

I have created controller file in sub folder of controller.

i have two type of sub folder for backend(admin) and frontend(user).

Structure of Controller

Controller
--backend
   ---admin.php
   ---dashboard.php
--frontend
   ---user.php

I want url for admin panel:

http://localhost/DemoSite/admin_panel/admin/dashboard

admin_panel want it in URL before every backend controller call

admin is Controller
dashboard is Function

For frontend :

http://localhost/DemoSite/user

I have done route like this :

$route['default_controller'] = 'frontend/user';
$route['admin/(:any)'] = "backend/$1";
$route['(:any)'] = "user/$1";

回答1:

Try to delete the last line in routes and create multiple routes to user:

//user routes
$route['default_controller'] = 'frontend/user';
$route['user'] = "frontend/user";

//admin routes
$route['admin/(:any)'] = "backend/$1";