CodeIgniter Forums
Dynamic Routes Issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Dynamic Routes Issue (/showthread.php?tid=65525)



Dynamic Routes Issue - wolfgang1983 - 06-22-2016

I am using database driven routes with my HMVC.

As shown here



PHP Code:
require_once(BASEPATH .'database/DB.php');

$db =& DB();

$query $db->get('layout');

$result $query->result_array();

$files scandir(APPPATH 'modules/catalog/controllers');

var_dump($files);

foreach(
$result as $row) {

    
$folder '';
                    
 
   $route[$row['route']] = 'catalog' '/' $folder '/' $row['route'] . '/index';
}

$route['rugby'] = 'catalog/super_rugby/rugby/index';
$route['rugby/(:any)'] = 'catalog/super_rugby/rugby/index/$1';
$route['rugby/(:any)/(:any)'] = 'catalog/super_rugby/rugby/index/$1/$2'


The $row['route'] produces a controller name I have set in database

I would like to know is it possible to detect which folder that file controller is in and use a $folder variable like above?

The var dump of scan dir


PHP Code:
array (size=5)
 
 0 => string '.' (length=1)
 
 1 => string '..' (length=2)
 
 2 => string 'common' (length=6)
 
 3 => string 'module' (length=6)
 
 4 => string 'super_rugby' (length=11
Update
I have tried it with this code have I done it correct to find files

PHP Code:
require_once(BASEPATH .'database/DB.php');

$db =& DB();

$query $db->get('layout');

$result $query->result_array();

$dirname APPPATH 'modules/catalog/controllers/';
$findme "*.php";
$dirs glob($dirname.'*'GLOB_ONLYDIR);
$files = array();

foreach(
$result as $row) {

    foreach(
$dirs as $d) {
        
$folder  basename($d);
    }

 
   $route[$row['route']] = 'catalog' '/' $folder '/' $row['route'] . '/index';
 
   $route[$row['route'] . '/(:any)'] = 'catalog' '/' $folder '/' $row['route'] . '/index/$1';
 
   $route[$row['route'] . '/(:any)/(:any)'] = 'catalog' '/' $folder '/' $row['route'] . '/index/$1/$2';