• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic Routes Issue

#1
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.