Phlyty\App::urlFor PHP Method

urlFor() public method

Generates a URL based on a named route
public urlFor ( string $route = null, array $params = [], array $options = [] ) : string
$route string Named Route instance
$params array Parameters to use in url generation, if any
$options array Router\RouteInterface-specific options to use in url generation, if any
return string
    public function urlFor($route = null, array $params = [], array $options = [])
    {
        if (null === $route) {
            if (-1 === $this->routeIndex) {
                throw new Exception\InvalidRouteException('Cannot call urlFor() with empty arguments; no route matched in this request');
            }
            $route = $this->routes[$this->routeIndex];
            $params = array_merge($this->params()->getParams(), $params);
        }
        if (is_string($route)) {
            if (!isset($this->namedRoutes[$route])) {
                throw new Exception\InvalidRouteException(sprintf('Route by name "%s" not found; cannot generate URL', $route));
            }
            $route = $this->namedRoutes[$route];
        }
        if (!$route instanceof Route) {
            throw new Exception\InvalidRouteException(sprintf('Invalid route type provided to %s; expects a string', __METHOD__));
        }
        return $this->request()->getBaseUrl() . $route->route()->assemble($params, $options);
    }