Example #1
0
 /**
  * 根据提供的 控制器 + 参数 构造对应的伪静态 URL
  *
  * @return 返回构造好的 URL
  *
  * @$siteBase  网站的根目录,比如  http://www.bangzhufu.com:8080
  *
  * @param string  $siteBase    网站路径,比如 http://www.bangzhufu.com
  * @param string  $controller  控制器 比如 '/User/Login'
  * @param array   $paramArray  参数列表,比如 array('username'=>'xxx', 'password'=>'xxx')
  * @param boolean $ignoreBase  是否忽略 BASE,一个网站的地址可能是 http://xxxx.com/tuan/team/index  其中 /tuan 就是 BASE,后面才是 Controller
  * @param boolean $withScheme  是否带 scheme,带scheme 为 http://www.xxx.com:82/ ,不带 scheme 就没有域名
  * @param boolean $static      是否生成静态参数,缺省为 null 不做任何操作,如果是 false 则生成  ?username=xxx&password=xxx, true 生成静态URL
  *
  * */
 public static function makeUrlWithSiteBase($siteBase, $controller, array $paramArray = null, $ignoreBase = false, $withScheme = false, $static = null)
 {
     global $f3;
     $makeStaticUrl = true === $static || null === $static && self::$isMakeStaticUrl;
     $url = '';
     $controller = trim($controller);
     if (Utils::isBlank($controller)) {
         $url = '#';
         goto out;
     }
     if (!$ignoreBase && '/' == $controller[0]) {
         $url .= $siteBase;
     }
     $url .= $controller;
     if (!empty($paramArray)) {
         if (!$makeStaticUrl) {
             // 生成标准的动态链接
             $url .= '?' . Route::combineParam('&', '=', $paramArray);
         } else {
             // 生成静态链接
             $url .= '/' . Route::combineParam(Route::$paramDelimiter, Route::$paramKeyValueDelimiter, $paramArray) . Route::$suffix;
         }
     } else {
         // 没有参数,除了首页之外也需要生成静态链接  /Cart/Show  生成为  /Cart/Show.html
         $url .= $makeStaticUrl && '/' != $controller && strrpos($controller, self::$suffix) !== strlen($controller) - strlen(self::$suffix) ? Route::$suffix : '';
     }
     if ($withScheme) {
         $url = Route::getDomain(true) . $url;
     }
     if (Route::$enableSessionIdUrl) {
         $url = Route::addParam($url, array(session_name() => session_id()));
     }
     out:
     return $url;
 }