Welcome Guest, Not a member yet? Register   Sign In
Multi Level controller not working
#3

[eluser]jaswinder_rana[/eluser]
Not sure if it's correct but following did it

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Router Class
*
* Extends CI Router

* @see        http://codeigniter.com
*/

class MY_Router extends CI_Router {
    /**
     * Validates the supplied segments.  Attempts to determine the path to
     * the controller.
     *
     * @access    private
     * @param    array
     * @return    array
     */    
    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-sub-folder?
        if (is_dir(APPPATH.'controllers/'.$segments[0].'/'.$segments[1]))
        {        
            // Set the directory and remove it from the segment array
            $this->set_directory($segments[0].'/'.$segments[1]);
            $segments = array_slice($segments, 2);
            
            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;
        }
        
        
        // Is the controller in a sub-folder?
        if (is_dir(APPPATH.'controllers/'.$segments[0]))
        {
            // Set the directory and remove it from the segment array
            $this->set_directory($segments[0]);
            $segments = array_slice($segments, 1);
            
            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
Multi Level controller not working - by El Forum - 12-30-2008, 12:41 PM
Multi Level controller not working - by El Forum - 12-30-2008, 01:18 PM
Multi Level controller not working - by El Forum - 12-30-2008, 01:26 PM
Multi Level controller not working - by El Forum - 12-30-2008, 02:30 PM
Multi Level controller not working - by El Forum - 12-30-2008, 02:51 PM
Multi Level controller not working - by El Forum - 12-30-2008, 03:41 PM
Multi Level controller not working - by El Forum - 12-30-2008, 03:45 PM
Multi Level controller not working - by El Forum - 12-30-2008, 03:48 PM
Multi Level controller not working - by El Forum - 12-30-2008, 03:52 PM
Multi Level controller not working - by El Forum - 12-30-2008, 03:56 PM
Multi Level controller not working - by El Forum - 12-30-2008, 03:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB