Browse Source

Add method Router::getUri($route_name = null) - Give me this uri on route_name is null, other another route uri from route_name.

master
Alexander Demidov 13 years ago
parent
commit
73ff07ce7d
  1. 5
      app/router/Route.php
  2. 26
      app/router/Router.php

5
app/router/Route.php

@ -55,6 +55,11 @@ class Route
return true;
}
public function getUri()
{
return '/' . $this->route;
}
public function getAction()
{
return $this->action . 'Action';

26
app/router/Router.php

@ -63,4 +63,30 @@ class Router
{
return $this->route;
}
public function routeIsExists($name)
{
return array_key_exists($name, $this->routes);
}
public function getRouteByName($name)
{
return $this->routes[$name];
}
static public function getUri($route_name = null)
{
$router = FrontController::getInstance()->getRouter();
if (is_null($route_name)) {
$route = $router->getRoute();
} else {
if ($router->routeIsExists($route_name)) {
$route = $router->getRouteByName($route_name);
} else {
$btrace = debug_backtrace();
throw new ErrorException('Unknown route handler: "' . $route_name . '". ' . 'Call from "' . $btrace[0]['file'] . '" on line ' . $btrace[0]['line'] . '.');
}
}
return $route->getUri();
}
}
Loading…
Cancel
Save