コード例 #1
0
 /**
  * Generate an url by a registred route
  *
  * @param string $routeName
  * @param array  $params
  * @return string
  */
 public function generate($routeName, array $params = array())
 {
     if (!$this->collection->has($routeName)) {
         throw new RouterException('Route not registred: ' . $routeName);
     }
     $routes = $this->collection->getAll();
     $route = $routes[$routeName];
     $controllerUrl = null;
     $actionUrl = null;
     foreach ($route->getController() as $key => $value) {
         $controllerUrl = $key;
     }
     foreach ($route->getAction() as $key => $value) {
         $actionUrl = $key;
     }
     return $controllerUrl . '/' . $actionUrl . '/' . implode('/', $this->detectParams($route, $params));
 }