CodeIgniter Forums
Route Helper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Route Helper (/showthread.php?tid=6027)



Route Helper - El Forum - 02-12-2008

[eluser]Pascal Kriete[/eluser]
Personally I extended the URL helper, but route helper seemed like a good name.

I've seen several people ask how they can get the current directory / controller / function since the release of 1.6, so I thought I should share.

Should be pretty self-explanatory.
Code:
function url_directory() {
    $route =& load_class('Router');
    $dir = substr_replace($route->directory, '', -1);  //Remove trailing slash
    return $dir;
}

function url_class() {
    $route =& load_class('Router');
    return $route->class;
}

function url_method() {
    $route =& load_class('Router');
    return $route->method;
}

function get_full_url() {
    $CI =& get_instance();
    $route =& load_class('Router');
    
    $full_route = $route->directory . $route->class.'/'.$route->method;
    return $full_route;
}

If anyone can tell me if this works with multiple directories (i.e. matchbox), that would be great.