Welcome Guest, Not a member yet? Register   Sign In
Re-Routing with Controllers in Subfolders
#1

[eluser]macigniter[/eluser]
I have controllers in a subfolder and also use some routing features for different languages. So let's say I have URIs like these:

Code:
www.domain.com/de/admin/overview
www.domain.com/en/admin/overview

I simply want to retrieve...

Code:
/admin/overview

...but cannot get it to work with $this->uri->ruri_string() which unfortunately does NOT include the subfolder admin. It always returns:

Code:
overview/index

I know I could be using $this->uri->uri_string() which will be returning:

Code:
/de/admin/overview

BUT since the routing will not always be used I need a solution which works whether routing is used or not. Does anyone have a solution for this!?

So the main question is:
How do I get the controller including a subfolder from a (possibly re-routed) URI?
#2

[eluser]macigniter[/eluser]
Looks like this will do the trick:

Code:
// this will return the re-routed uri string with a possible sub-folder

$ruri_string = '/'.trim(trim($this->router->fetch_directory(), '/').'/'.trim($this->uri->ruri_string(), '/'), '/');

Since I believe that the sub-directory should be added to the ruri_string I created a MY_URI.php library file that includes the following:

Code:
class MY_URI extends CI_URI {

    function My_URI()
    {
        parent::CI_URI();
    }

    /**
     * Fetch the entire Re-routed URI string
     * WITH a possible sub-folder
     *
     * @access    public
     * @return    string
     */
    function ruri_string()
    {
        $CI =& get_instance();

        return '/'.trim(trim($CI->router->fetch_directory(), '/').'/'.implode('/', $CI->uri->rsegment_array()), '/');
    }

}




Theme © iAndrew 2016 - Forum software by © MyBB