Welcome Guest, Not a member yet? Register   Sign In
Creating a database-driven dynamic route **SOLVED**
#6

[eluser]wiredesignz[/eluser]
Modular Extensions PHP5 and Modular Separation PHP5 version 1.9 using $route['404'].

application/libraries/My_Router.php
Code:
class MY_Router extends CI_Router
{
    private $module;
    
    public function fetch_module() {
        return $this->module;
    }
    
    public function _validate_request($segments) {        
        
        /* locate module controller */
        if ($located = $this->locate($segments)) return $located;
        
        /* application controller exists? */            
        if(is_file(APPPATH.'controllers/'.$segments[0].EXT)) {
            return $segments;
        }        
    
        list($directory, $controller) = array_pad($segments, 2, NULL);
        
        /* application sub-directory controller exists? */
        if(is_file(APPPATH.'controllers/'.$directory.'/'.$controller.EXT)) {
            $this->directory = array_shift($segments).'/';
            return $segments;
        }        
        
        /* use a default 404 controller */
        if (isset($this->routes['404']) AND $segments = explode('/', $this->routes['404'])) {
            
            /* locate 404 controller in a module? */
            if ($located = $this->locate($segments)) return $located;

            /* is 404 controller in application? */
            if (is_file(APPPATH.'controllers/'.$this->routes['404'].EXT)) {
                if (count($segments) > 1) $this->directory = array_shift($segments).'/';
                return $segments;
            }
        }
        
        /* no controller found */
        show_404();
    }

    public function locate($segments) { ... }
}


Messages In This Thread
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-12-2009, 08:20 PM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-12-2009, 08:31 PM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-12-2009, 09:02 PM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 01:18 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 03:59 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 04:11 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 04:19 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 04:38 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 07:58 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 11-13-2009, 08:29 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 01-22-2010, 10:54 AM
Creating a database-driven dynamic route **SOLVED** - by El Forum - 02-07-2012, 04:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB