CodeIgniter Forums

Full Version: Dynamic Routes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all, I'm new to CI.
In my future project, we will have a menu structure like this:
Menu1
--Submenu1
--Submenu2
--[...]
Menu2
--Submenu3
--Submenu4
[...]

So, many menus, and each of them will have many submenus (many submenus will have a CRUD, or similar).
My problem is making the routes to all this pages, I would like to organize the Controllers inside folders (with the menu's name) and each submenu would be a Controller, like this:
/app/Controller/Menu1/Submenu1.php
/app/Controller/Menu1/Submenu2.php
/app/Controller/Menu2/Submenu1.php
etc...

But at the same time, I don't want to create one entry in the Routes.php file for each submenu, is there a way to create a route that simply takes the path URI and search in the folders for that exact values?
ROUTES

$route['sample1/(:any)'] = 'ctrl1/index/$1';
$route['sample1'] = 'ctrl1/index';

$route['sample2/(:any)'] = 'ctrl2/index/$1';
$route['sample2'] = 'ctrl2/index';


Ctrl1
function index($i1,$i2){
// your code for model and view
}

Ctrl2
function index($i1,$i2){
// your code for model and view
}
(03-15-2019, 12:56 AM)lorenzoallopez91 Wrote: [ -> ]ROUTES

$route['sample1/(:any)'] = 'ctrl1/index/$1';
$route['sample1'] = 'ctrl1/index';

$route['sample2/(:any)'] = 'ctrl2/index/$1';
$route['sample2'] = 'ctrl2/index';


Ctrl1
function index($i1,$i2){
  // your code for model and view
}

Ctrl2
function index($i1,$i2){
  // your code for model and view
}

I'm sorry but it didn't worked out, and I didn't find any routing with this notation in the documentation... My routes are defined by:

$routes->get('/callcenter', 'Callcenter::index');
$routes->get('/callcenter/(:any)', 'Callcenter::$1');