• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to access controllers in subdirectories

#2
[eluser]WanWizard[/eluser]
A quick scan of the router library shows that controllers in subdirectories are not supported when using query strings.

This MY_Router extension might fix this. Note: I haven't tested this, and it fails if you include more than 1 directory.
Code:
<?php
class MY_Router extends CI_Router
{
    /**
     * Set the route mapping
     *
     * This function supports a directory in the controller_trigger string
     *
     * @access    private
     * @return    void
     */
    function _set_routing()
    {
        // Are query strings enabled in the config file?
        // If so, we're done since segment based URIs are not used with query strings.
        if ($this->config->item('enable_query_strings') === TRUE AND isset($_GET[$this->config->item('controller_trigger')]))
        {
            $controller = explode('/', $_GET[$this->config->item('controller_trigger')]);
            if ( count($controller) == 1 )
            {
                $this->set_class(trim($this->uri->_filter_uri($controller[0])));
            }
            else
            {
                $this->set_directory(trim($this->uri->_filter_uri($controller[0])));
                $this->set_class(trim($this->uri->_filter_uri($controller[1])));
            }

            if (isset($_GET[$this->config->item('function_trigger')]))
            {
                $this->set_method(trim($this->uri->_filter_uri($_GET[$this->config->item('function_trigger')])));
            }
            
            return;
        }
        else
        {
            return parent::_set_routing();
        }
}

/* End of file MY_Router.php */
/* Location: ./application/libraries/MY_Router.php */


Messages In This Thread
How to access controllers in subdirectories - by El Forum - 12-01-2010, 04:08 PM
How to access controllers in subdirectories - by El Forum - 12-01-2010, 04:23 PM
How to access controllers in subdirectories - by El Forum - 12-01-2010, 11:06 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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