Autarky\Routing\Router::getRoute PHP Method

getRoute() public method

public getRoute ( $name )
    public function getRoute($name)
    {
        if (!isset($this->namedRoutes[$name])) {
            throw new \InvalidArgumentException("Route with name {$name} not found.");
        }
        return $this->namedRoutes[$name];
    }

Usage Example

Beispiel #1
0
 /**
  * Get the URL to a named route.
  *
  * @param  string $name
  * @param  array  $params
  * @param  bool   $relative
  *
  * @return string
  */
 public function getRouteUrl($name, array $params = array(), $relative = false)
 {
     $route = $this->router->getRoute($name);
     $routeParams = [];
     $query = [];
     foreach ($params as $key => $value) {
         if (is_int($key)) {
             $routeParams[] = $value;
         } else {
             $query[$key] = $value;
         }
     }
     $path = $this->routePathGenerator->getRoutePath($route, $routeParams);
     if ($query) {
         $path .= '?' . http_build_query($query);
     }
     if ($relative) {
         $root = $this->requests->getCurrentRequest()->getBaseUrl();
     } else {
         $root = $this->getRootUrl();
     }
     return $root . $path;
 }