Welcome Guest, Not a member yet? Register   Sign In
Dynamic Routes
#1

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?
Reply
#2

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
}
Reply
#3

(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');
Reply




Theme © iAndrew 2016 - Forum software by © MyBB