function url_for($route, $vars = 0)
{
    global $_routes;
    $og_route = $route;
    $route = url_explode($_routes[$route]['url']);
    foreach ($route as $key => $val) {
        # Check if the current route iteration is that of a wildcard.
        # We'll modify our $route array to include any passed values.
        # E.g. /this/:var will return this/passedVar
        if (is_route_wildcard($val)) {
            $r = str_replace(':', '', $val);
            if ($vars[$r]) {
                $route[$key] = $vars[$r];
            } else {
                die('missing var!');
            }
        }
    }
    # Return the URL.
    return '/' . implode('/', $route);
}
Exemplo n.º 2
0
require 'user/config/user.php';
# Define an array for controller's vars.
$_controller = array();
$_controller['current_url'] = curr_url();
$_url_match = 0;
# Check and see if we have a route match
foreach ($_routes as $_route) {
    $_controller['route_url'] = url_explode($_route['url']);
    # Check for an array size match between the current url and the current stored url iteration.
    if (count($_controller['current_url']) == count($_controller['route_url'])) {
        log_me("Looks like we've got a url count match on -- " . implode('/', $_controller['route_url']));
        $size = count($_controller['current_url']);
        # Compare the urls
        for ($i = 0; $i < $size; ++$i) {
            # Let's catch the route wildcards
            if (is_route_wildcard($_controller['route_url'][$i])) {
                # We know we're dealing with a wildcard--let's find out if it's a module or action
                if ($_controller['route_url'][$i] == ':module') {
                    $_module = str_replace(':', '', $_controller['current_url'][$i]);
                    log_me("The following module wildcard was found -- " . $_module);
                }
                if ($_controller['route_url'][$i] == ':action') {
                    $_action = str_replace(':', '', $_controller['current_url'][$i]);
                    log_me("The following action wildcard was found -- " . $_action);
                }
                if ($_module && $_action) {
                    $_url_match = 1;
                    log_me("Looks like we've got both a module and action wildcard; setting" . ' $_url_match to true');
                }
                # Make sure that the wildcards aren't matching on :module or :action, as these are reserved wildcards.
                if ($_controller['route_url'][$i] != ':module' && $_controller['route_url'][$i] != ':action') {