<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Url 幫助類 Url 幫助類提供一系列的靜態方法來幫助管理 URL。 ## 獲得通用 URL 有兩種獲取通用 URLS 的方法 :當前請求的 home URL 和 base URL 。 為了獲取 home URL ,使用如下代碼: ~~~ $relativeHomeUrl = Url::home(); $absoluteHomeUrl = Url::home(true); $httpsAbsoluteHomeUrl = Url::home('https'); ~~~ 如果沒有傳任何參數,這個方法將會生成相對 URL 。你可以傳?`true`?來獲得一個針對當前協議的絕對 URL; 或者,你可以明確的指定具體的協議類型(?`https`?,?`http`?)。 如下代碼可以獲得當前請求的 base URL: `````php $relativeBaseUrl = Url::base(); $absoluteBaseUrl = Url::base(true); $httpsAbsoluteBaseUrl = Url::base('https');?````` 這個方法的調用方式和?`Url::home()`?的完全一樣。 ## 創建 URLs 為了創建一個給定路由的 URL 地址,請使用?`Url::toRoute()`方法。 這個方法使用 \yii\web\UrlManager 來創建一個 URL : ~~~ $url = Url::toRoute(['product/view', 'id' => 42]); ~~~ 你可以指定一個字符串來作為路由,如:?`site/index`?。如果想要指定將要被創建的 URL 的附加查詢參數, 你同樣可以使用一個數組來作為路由。數組的格式須為: ~~~ // generates: /index.php?r=site/index&param1=value1&param2=value2 ['site/index', 'param1' => 'value1', 'param2' => 'value2'] ~~~ 如果你想要創建一個帶有 anchor 的 URL ,你可以使用一個帶有?`#`?參數的數組。比如: ~~~ // generates: /index.php?r=site/index&param1=value1#name ['site/index', 'param1' => 'value1', '#' => 'name'] ~~~ 一個路由既可能是絕對的又可能是相對的。一個絕對的路由以前導斜杠開頭(如:?`/site/index`), 而一個相對的路由則沒有(比如:?`site/index`?或者?`index`)。一個相對的路由將會按照如下規則轉換為絕對路由: * 如果這個路由是一個空的字符串,將會使用當前 \yii\web\Controller::route 作為路由; * 如果這個路由不帶任何斜杠(比如?`index`?),它會被認為是當前控制器的一個 action ID, 然后將會把 \yii\web\Controller::uniqueId 插入到路由前面。 * 如果這個路由不帶前導斜杠(比如:?`site/index`?),它會被認為是相對當前模塊(module)的路由, 然后將會把 \yii\base\Module::uniqueId 插入到路由前面。 從2.0.2版本開始,你可以用?[alias](http://www.yiichina.com/doc/guide/2.0/concept-aliases)?來指定一個路由。 在這種情況下, alias 將會首先轉換為實際的路由, 然后會按照上述規則轉換為絕對路由。 以下是該方法的一些例子: ~~~ // /index.php?r=site/index echo Url::toRoute('site/index'); // /index.php?r=site/index&src=ref1#name echo Url::toRoute(['site/index', 'src' => 'ref1', '#' => 'name']); // /index.php?r=post/edit&id=100 assume the alias "@postEdit" is defined as "post/edit" echo Url::toRoute(['@postEdit', 'id' => 100]); // http://www.example.com/index.php?r=site/index echo Url::toRoute('site/index', true); // https://www.example.com/index.php?r=site/index echo Url::toRoute('site/index', 'https'); ~~~ 還有另外一個方法?`Url::to()`?和 toRoute() 非常類似。這兩個方法的唯一區別在于,前者要求一個路由必須用數組來指定。 如果傳的參數為字符串,它將會被直接當做 URL 。 `Url::to()`?的第一個參數可以是: * 數組:將會調用 toRoute() 來生成URL。比如:?`['site/index']`,?`['post/index', 'page' => 2]`?。 詳細用法請參考 toRoute() 。 * 帶前導?`@`?的字符串:它將會被當做別名, 對應的別名字符串將會返回。 * 空的字符串:當前請求的 URL 將會被返回; * 普通的字符串:返回本身。 當?`$scheme`?指定了(無論是字符串還是 true ),一個帶主機信息(通過 \yii\web\UrlManager::hostInfo 獲得) 的絕對 URL 將會被返回。如果?`$url`?已經是絕對 URL 了, 它的協議信息將會被替換為指定的( https 或者 http )。 以下是一些使用示例: ~~~ // /index.php?r=site/index echo Url::to(['site/index']); // /index.php?r=site/index&src=ref1#name echo Url::to(['site/index', 'src' => 'ref1', '#' => 'name']); // /index.php?r=post/edit&id=100 assume the alias "@postEdit" is defined as "post/edit" echo Url::to(['@postEdit', 'id' => 100]); // the currently requested URL echo Url::to(); // /images/logo.gif echo Url::to('@web/images/logo.gif'); // images/logo.gif echo Url::to('images/logo.gif'); // http://www.example.com/images/logo.gif echo Url::to('@web/images/logo.gif', true); // https://www.example.com/images/logo.gif echo Url::to('@web/images/logo.gif', 'https'); ~~~ 從2.0.3版本開始,你可以使用 yii\helpers\Url::current() 來創建一個基于當前請求路由和 GET 參數的 URL。 你可以通過傳遞一個`$params`?給這個方法來添加或者刪除 GET 參數。 例如: ~~~ // assume $_GET = ['id' => 123, 'src' => 'google'], current route is "post/view" // /index.php?r=post/view&id=123&src=google echo Url::current(); // /index.php?r=post/view&id=123 echo Url::current(['src' => null]); // /index.php?r=post/view&id=100&src=google echo Url::current(['id' => 100]); ~~~ ## 記住 URLs 有時,你需要記住一個 URL 并在后續的請求處理中使用它。 你可以用以下方式達到這個目的: ~~~ // Remember current URL Url::remember(); // Remember URL specified. See Url::to() for argument format. Url::remember(['product/view', 'id' => 42]); // Remember URL specified with a name given Url::remember(['product/view', 'id' => 42], 'product'); ~~~ 在后續的請求處理中,可以用如下方式獲得記住的 URL: ~~~ $url = Url::previous(); $productUrl = Url::previous('product'); ~~~ ## 檢查相對 URLs 你可以用如下代碼檢測一個 URL 是否是相對的(比如,包含主機信息部分)。 ~~~ $isRelative = Url::isRelative('test/it'); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看