Cml\Http\Response::url PHP Method

url() public static method

URL组装 支持不同URL模式 eg: \Cml\Http\Response::url('Home/Blog/cate/id/1')
public static url ( string $url = '', integer $echo = 1 ) : string
$url string URL表达式 路径/控制器/操作/参数1/参数1值/.....
$echo integer 是否输出 1输出 0 return
return string
    public static function url($url = '', $echo = 1)
    {
        $return = '';
        // 解析URL
        if (empty($url)) {
            throw new \InvalidArgumentException(Lang::get('_NOT_ALLOW_EMPTY_', 'url'));
            //'U方法参数出错'
        }
        // URL组装
        $delimiter = Config::get('url_pathinfo_depr');
        $url = ltrim($url, '/');
        $url = implode($delimiter, explode('/', $url));
        if (Config::get('url_model') == 1) {
            $return = $_SERVER['SCRIPT_NAME'] . '/' . $url;
        } elseif (Config::get('url_model') == 2) {
            $return = Cml::getContainer()->make('cml_route')->getSubDirName() . $url;
        } elseif (Config::get('url_model') == 3) {
            $return = $_SERVER['SCRIPT_NAME'] . '?' . Config::get('var_pathinfo') . '=/' . $url;
        }
        $return .= Config::get('url_model') == 2 ? Config::get('url_html_suffix') : '';
        $return = Secure::filterScript($return);
        if ($echo === 1) {
            echo $return;
        } else {
            return $return;
        }
        return '';
    }

Usage Example

示例#1
0
 /**
  * 解析一个静态资源的地址
  *
  * @param string $resource 文件地址
  */
 public static function parseResourceUrl($resource = '')
 {
     if ($GLOBALS['debug'] && CML_IS_MULTI_MODULES) {
         //简单判断没有.的时候当作是目录不加版本号
         $isDir = strpos($resource, '.') === false ? true : false;
         $file = Response::url("cmlframeworkstaticparse/{$resource}", false);
         $isDir || ($file .= (\Cml\Config::get("url_model") == 3 ? "&v=" : "?v=") . Cml::$nowTime);
     } else {
         $file = Config::get("static__path", \Cml\Route::$urlParams["root"] . "public/{$resource}");
     }
     echo $file;
 }
All Usage Examples Of Cml\Http\Response::url