Example #1
0
 protected function createLinkString($route = '', $params = array())
 {
     // Current pages
     if (!$route || $route == '.') {
         $controller = $this->getController();
         $action = $this->getAction(null);
     } elseif ($route == '/') {
         $controller = null;
         $action = null;
     } elseif ($route == '..' || $route == '../') {
         $controller = $this->getController();
         $action = null;
     } else {
         // Absolute route
         if (substr($route, 0, 1) == '/') {
             list($controller, $action) = Route::getActionAndControllerFromRoute($route);
         } elseif (strlen($route) > 3 && substr($route, 0, 3) == '../') {
             $_route = substr($route, 3);
             if (substr($_route, -1, 1) == '/') {
                 $_route = substr($_route, 0, -1);
             }
             $controller = $this->getController();
             $action = $_route;
         } else {
             throw new Exception('Request link: syntax error');
         }
     }
     $config = Config::getInstance();
     if ($controller == $config->defaultController && !$action) {
         $controller = null;
     }
     $url = $config->getLinkCreationURL();
     $url .= Route::computeRoute($controller, $action);
     $addSid = $config->sessionUseURL && defined('SID') && SID && !array_key_exists(Session::NAME, $_COOKIE);
     $sid = $addSid ? htmlspecialchars(SID) : '';
     $queryString = http_build_query($params, '', '&');
     return $url . ($sid || $queryString ? '?' : '') . $sid . ($sid ? '&' : '') . $queryString . ($this->fragment ? '#' . $this->fragment : '');
 }