Example #1
0
 public function getUrlByRoute($routeName, $params = array(), $absolute = true)
 {
     if (!is_array($params)) {
         throw new \Exception('Variable "params" must be array ');
     }
     $response = new Response();
     if (array_key_exists($routeName, $this->routes)) {
         $route = $this->routes[$routeName];
     } else {
         throw new \Exception('Not found match for route ' . $routeName);
     }
     $url = '';
     if ($this->apacheRewriteMode == 1) {
         $url = '/index.php';
     }
     if ($absolute) {
         $url = $response->getPrepareUrl() . $url;
     }
     $url = $url . '/' . $routeName;
     if (count($route['params']) == 0) {
         return $url;
     }
     if (count($params) == 0) {
         throw new \Exception('Don`t set value for all parameters of route ' . $routeName);
     }
     foreach ($params as $param) {
         $url = $url . '/' . $param;
     }
     return $url;
 }