CodeIgniter Forums
How to access controllers in subdirectories - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to access controllers in subdirectories (/thread-36445.html)



How to access controllers in subdirectories - El Forum - 12-01-2010

[eluser]André Padez[/eluser]
Hi everyone,

i am really new to CI, and i was asked to reuse an application that was built last christmas.
I got around most of it, but now i am stuck with what i think should be an easy task.

So, i am working with query strings like:
Code:
http://www.myapp.com/index.php?c=maincontroller&m=index

in my controllers folder, i hava a subfolder called 'backoffice' with three controllers inside. How can i point my url so i can reach 'backoffice/donations.php' ?

thank you in advance

André Alçada Padez


How to access controllers in subdirectories - El Forum - 12-01-2010

[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 */



How to access controllers in subdirectories - El Forum - 12-01-2010

[eluser]jasonjack[/eluser]
hey this idea did not come in ma mind. i can use this. i will try n tel u later..