Welcome Guest, Not a member yet? Register   Sign In
Controllers in Unlimited Nested Folders
#34

[eluser]xwero[/eluser]
Try this overloaded _valid_request method
Code:
class MY_Router extends CI_Router
{
    function _validate_request($segments)
    {
        // Does the requested controller exist in the root folder?
        if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            return $segments;
        }

        // Is the controller in a sub-folder?
        $dir = '';
        $slice_offset = 0;
        // loop trough the segments until the segment is no directory
        foreach($segments as $segment)
        {
            if(strlen($dir) > 0){ $dir .= '/'; }
            if(is_dir(APPPATH.'controllers/'.$dir.$segment))
            {
                $dir .= $segment;
                $slice_offset++;
            }
            else
            {
                break;
            }
        }
        if($dir != '')
        {
            // Set the directory and remove it from the segment array
            $this->directory($dir);
            $segments = array_slice($segments, $slice_offset);
            
            if (count($segments) > 0)
            {
                // Does the requested controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
                {
                    show_404($this->fetch_directory().$segments[0]);    
                }
            }
            else
            {
                $this->set_class($this->default_controller);
                $this->set_method('index');
            
                // Does the default controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
                {
                    $this->directory = '';
                    return array();
                }
            
            }
                
            return $segments;
        }
    
        // Can't find the requested controller...
        show_404($segments[0]);    
    }
}


Messages In This Thread
Controllers in Unlimited Nested Folders - by El Forum - 07-09-2007, 11:56 AM
Controllers in Unlimited Nested Folders - by El Forum - 07-09-2007, 02:27 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-09-2007, 04:31 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-10-2007, 12:46 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-10-2007, 01:40 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-13-2007, 08:57 AM
Controllers in Unlimited Nested Folders - by El Forum - 07-13-2007, 09:13 AM
Controllers in Unlimited Nested Folders - by El Forum - 07-17-2007, 04:20 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-19-2007, 09:32 AM
Controllers in Unlimited Nested Folders - by El Forum - 07-19-2007, 09:39 AM
Controllers in Unlimited Nested Folders - by El Forum - 07-20-2007, 11:45 AM
Controllers in Unlimited Nested Folders - by El Forum - 07-20-2007, 12:36 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-25-2007, 09:36 AM
Controllers in Unlimited Nested Folders - by El Forum - 07-25-2007, 02:02 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-25-2007, 02:35 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-25-2007, 03:00 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-25-2007, 05:16 PM
Controllers in Unlimited Nested Folders - by El Forum - 07-25-2007, 06:04 PM
Controllers in Unlimited Nested Folders - by El Forum - 09-11-2007, 09:37 PM
Controllers in Unlimited Nested Folders - by El Forum - 10-10-2007, 11:23 AM
Controllers in Unlimited Nested Folders - by El Forum - 01-10-2008, 04:18 PM
Controllers in Unlimited Nested Folders - by El Forum - 01-11-2008, 06:18 AM
Controllers in Unlimited Nested Folders - by El Forum - 01-11-2008, 07:13 AM
Controllers in Unlimited Nested Folders - by El Forum - 01-22-2008, 10:53 PM
Controllers in Unlimited Nested Folders - by El Forum - 01-23-2008, 02:22 PM
Controllers in Unlimited Nested Folders - by El Forum - 01-23-2008, 02:51 PM
Controllers in Unlimited Nested Folders - by El Forum - 01-23-2008, 02:57 PM
Controllers in Unlimited Nested Folders - by El Forum - 01-23-2008, 03:02 PM
Controllers in Unlimited Nested Folders - by El Forum - 02-04-2008, 06:38 AM
Controllers in Unlimited Nested Folders - by El Forum - 02-04-2008, 07:31 AM
Controllers in Unlimited Nested Folders - by El Forum - 02-17-2008, 01:37 AM
Controllers in Unlimited Nested Folders - by El Forum - 03-22-2008, 08:02 PM
Controllers in Unlimited Nested Folders - by El Forum - 03-22-2008, 10:34 PM
Controllers in Unlimited Nested Folders - by El Forum - 03-23-2008, 01:41 AM
Controllers in Unlimited Nested Folders - by El Forum - 08-05-2008, 12:52 AM
Controllers in Unlimited Nested Folders - by El Forum - 08-05-2008, 07:20 PM
Controllers in Unlimited Nested Folders - by El Forum - 03-23-2009, 04:04 AM
Controllers in Unlimited Nested Folders - by El Forum - 04-03-2009, 08:03 PM
Controllers in Unlimited Nested Folders - by El Forum - 04-28-2009, 05:37 PM
Controllers in Unlimited Nested Folders - by El Forum - 05-07-2009, 11:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB