/** * Generate the url for the specified page. * * @param int $page * @return String */ public function url($page = 1) { // Clean the page number $page = max(1, (int) $page); // No page number in URLs to first page if ($page === 1 and !$this->config['first_page_in_url']) { $page = NULL; } $params = array_merge($this->route_params, array($this->config['param'] => $page)); $suffix = ''; if ($this->query != FALSE) { if (is_string($this->query)) { $suffix = $this->query != FALSE ? '?' . $this->query . '=' . $this->request->query($this->query) : ''; } elseif (is_array($this->query)) { $suffix = '?'; $first = TRUE; foreach ($this->query as $q) { if ($first) { $first = FALSE; $suffix .= $q . '=' . $this->request->query($q); } else { $suffix .= '&' . $q . '=' . $this->request->query($q); } } } } return URL::site($this->route->uri($params)) . $suffix; }
/** * Generates a translated URI for the current route based on the parameters given * * @param array $params parameters for URI * @param string $lang target language, defaults to I18n::$lang * @return string URI in target language * @uses Lang::$i18n_routes * @uses Route::uri * @uses I18n::$lang * @uses Route::map */ public function uri(array $params = NULL, $lang = NULL) { // Forced language $forced_language = $lang !== NULL; if ($lang === NULL) { // Set target language to current language $lang = Lang::shortcode(I18n::$lang); } if (!Lang::$i18n_routes) { // i18n routes are off, build URI $uri = parent::uri($params); if (Lang::$default_prepended or Request::$lang !== Lang::$default and $lang !== Lang::$default or $forced_language and $lang !== Lang::$default) { // Prepend the target language to the URI if needed $uri = $lang . '/' . ltrim($uri, '/'); } // Return URI with or without language return $uri; } // Make sure text values are in correct language $this->translate_route($lang, FALSE); if ($params !== NULL) { // Translation required foreach ($params as $label => &$param) { if (isset($this->_translate['<' . $label . '>']) or isset($this->_translate[$param])) { // Translate param $param = Route::map($param, $lang); } } } // Build URI $uri = parent::uri($params); if (Lang::$default_prepended or Request::$lang !== Lang::$default and $lang !== Lang::$default or $forced_language and $lang !== Lang::$default) { // Prepend the target language to the URI if needed $uri = $lang . '/' . ltrim($uri, '/'); } return $uri; }