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

(This post was last modified: 06-22-2016, 05:04 AM by wolfgang1983.)

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';

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB