Welcome Guest, Not a member yet? Register   Sign In
Dynamic Route to Specific Controller
#11

[eluser]solepixel[/eluser]
Ok, this is what I ended up with:

Code:
global $DB_ROUTES;

list($uri, $qs) = (strpos($_SERVER['REQUEST_URI'], '?') !== false) ? explode('?', $_SERVER['REQUEST_URI']) : array($_SERVER['REQUEST_URI'],'');

$route = $uri;


if($uri != '/'){
    $uri = trim($uri, '/');
    
    $route = trim($route, '/');
    $route = str_replace('-', '_', $route);
}
if($row->controller){
    $path = ($row->controller == '/') ? 'index_controller' : trim($row->controller, '/');
    
    if($path != $uri){
    
        $route_uri = trim($row->uri, '/');
        $remainder = '/'.trim(str_replace($route_uri, '', $uri), '/');
        if($remainder == '/'){
            $remainder = '';
        }
            
        $uri = str_replace('-', '_', $uri);
        $DB_ROUTES[$uri] = $path.$remainder;
        $DB_ROUTES[$uri.'/(.*)'] = $path.$remainder.'/$1';
            
    }
        
} else {
    // insert index into global variable
    $DB_ROUTES[$route] = 'content/'.(($uri == '/') ? 'root' : $uri);
}
#12

[eluser]John_Betong[/eluser]
This is the way I manage to get my routing to work: by adding index

Link fixed - script modifed to use CI_Controller instead of Controller.
 
 
 




Theme © iAndrew 2016 - Forum software by © MyBB