CodeIgniter Forums
Dynamic Routes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Dynamic Routes (/showthread.php?tid=73061)



Dynamic Routes - GuilhermeBiz - 03-14-2019

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?


RE: Dynamic Routes - lorenzoallopez91 - 03-14-2019

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
}


RE: Dynamic Routes - GuilhermeBiz - 03-15-2019

(03-14-2019, 11:56 PM)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');