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

#1
[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

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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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