亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

?? ??? ??
閱讀前篇 簡介 Yii 是什么 從 Yii 1.1 升級 入門 安裝 Yii 運行應(yīng)用 第一次問候 使用Forms 數(shù)據(jù)庫應(yīng)用 使用 Gii 生成代碼 進階 應(yīng)用結(jié)構(gòu) 概述 入口腳本 應(yīng)用(Applications) 應(yīng)用組件(Application Components) 控制器(Controllers) 模型(Models) 視圖(views) 模塊(Modules) 過濾器(Filters) 小部件(Widgets) 前端資源(Assets) 擴展(Extensions) 請求處理 運行概述 啟動引導(dǎo)(Bootstrapping) 路由和創(chuàng)建URL 請求(Requests) 響應(yīng)(Responses) Sessions 和 Cookies 錯誤處理(Handling Errors) 日志(Logging) 關(guān)鍵概念 組件(Component) 屬性(Property) 事件(Events) 行為(Behaviors) 配置(Configurations) 別名(Aliases) 類自動加載(Autoloading) 服務(wù)定位器(Service Locator) 依賴注入容器(Dependency Injection Container) 配合數(shù)據(jù)庫工作 數(shù)據(jù)庫訪問 (Data Access Objects) 查詢生成器(Query Builder) 活動記錄(Active Record) 數(shù)據(jù)庫遷移(Migrations) Sphinx Redis MongoDB Elasticsearch 接收用戶數(shù)據(jù) 創(chuàng)建表單(Creating Forms) 輸入驗證(Validating Input) 文件上傳(Uploading Files) 收集列表輸入(Collecting Tabular Input) 多模型的復(fù)合表單(Getting Data for Multiple Models) 顯示數(shù)據(jù) 格式化輸出數(shù)據(jù)(Data Formatting) 分頁(Pagination) 排序(Sorting) 數(shù)據(jù)提供器(Data Providers) 數(shù)據(jù)小部件(Data Widgets) 客戶端腳本使用(Working with Client Scripts) 主題(Theming) 安全 認證(Authentication) 授權(quán)(Authorization) 處理密碼(Working with Passwords) 客戶端認證(Auth Clients) 最佳安全實踐(Best Practices) 緩存 概述 數(shù)據(jù)緩存 片段緩存 頁面緩存 HTTP 緩存 RESTfull Web服務(wù) 快速入門(Quick Start) 資源(Resources) 控制器(Controllers) 路由(Routing) 格式化響應(yīng)(Response Formatting) 授權(quán)認證(Authentication) 速率限制(Rate Limiting) 版本(Versioning) 錯誤處理(Error Handling) 開發(fā)工具 調(diào)試工具欄和調(diào)試器 使用Gii生成代碼 生成API文檔 測試 概述(Overview) 配置測試環(huán)境(Testing environment setup) 單元測試(Unit Tests) 功能測試(Function Tests) 驗收測試(Acceptance Tests) 測試夾具(Fixtures) 高級專題 高級應(yīng)用模板 創(chuàng)建自定義應(yīng)用程序結(jié)構(gòu) 控制臺命令 核心驗證器(Core Validators) 國際化 收發(fā)郵件 性能優(yōu)化 共享主機環(huán)境 模板引擎 集成第三方代碼 小部件 Bootstrap 小部件 Jquery UI 助手類 概述 Array 助手(ArrayHelper) Html 助手(Html) Url 助手(Url)
??

Url 助手

Url 幫助類

Url 幫助類提供一系列的靜態(tài)方法來幫助管理 URL。

獲得通用 URL

有兩種獲取通用 URLS 的方法 :當(dāng)前請求的 home URL 和 base URL 。 為了獲取 home URL ,使用如下代碼:

$relativeHomeUrl = Url::home();
$absoluteHomeUrl = Url::home(true);
$httpsAbsoluteHomeUrl = Url::home('https');

如果沒有傳任何參數(shù),這個方法將會生成相對 URL 。你可以傳?true?來獲得一個針對當(dāng)前協(xié)議的絕對 URL; 或者,你可以明確的指定具體的協(xié)議類型(?https?,?http?)。

如下代碼可以獲得當(dāng)前請求的 base URL:

`php $relativeBaseUrl = Url::base(); $absoluteBaseUrl = Url::base(true); $httpsAbsoluteBaseUrl = Url::base('https');?`

這個方法的調(diào)用方式和?Url::home()?的完全一樣。

創(chuàng)建 URLs

為了創(chuàng)建一個給定路由的 URL 地址,請使用?Url::toRoute()方法。 這個方法使用 \yii\web\UrlManager 來創(chuàng)建一個 URL :

$url = Url::toRoute(['product/view', 'id' => 42]);

你可以指定一個字符串來作為路由,如:?site/index?。如果想要指定將要被創(chuàng)建的 URL 的附加查詢參數(shù), 你同樣可以使用一個數(shù)組來作為路由。數(shù)組的格式須為:

// generates: /index.php?r=site/index&param1=value1&param2=value2
['site/index', 'param1' => 'value1', 'param2' => 'value2']

如果你想要創(chuàng)建一個帶有 anchor 的 URL ,你可以使用一個帶有?#?參數(shù)的數(shù)組。比如:

// generates: /index.php?r=site/index&param1=value1#name
['site/index', 'param1' => 'value1', '#' => 'name']

一個路由既可能是絕對的又可能是相對的。一個絕對的路由以前導(dǎo)斜杠開頭(如:?/site/index), 而一個相對的路由則沒有(比如:site/index?或者?index)。一個相對的路由將會按照如下規(guī)則轉(zhuǎn)換為絕對路由:

  • 如果這個路由是一個空的字符串,將會使用當(dāng)前 \yii\web\Controller::route 作為路由;
  • 如果這個路由不帶任何斜杠(比如?index?),它會被認為是當(dāng)前控制器的一個 action ID, 然后將會把 \yii\web\Controller::uniqueId 插入到路由前面。
  • 如果這個路由不帶前導(dǎo)斜杠(比如:?site/index?),它會被認為是相對當(dāng)前模塊(module)的路由, 然后將會把 \yii\base\Module::uniqueId 插入到路由前面。

從2.0.2版本開始,你可以用?alias?來指定一個路由。 在這種情況下, alias 將會首先轉(zhuǎn)換為實際的路由, 然后會按照上述規(guī)則轉(zhuǎn)換為絕對路由。

以下是該方法的一些例子:

// /index.php?r=site/indexecho Url::toRoute('site/index');

// /index.php?r=site/index&src=ref1#nameecho 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/indexecho Url::toRoute('site/index', true);

// https://www.example.com/index.php?r=site/indexecho Url::toRoute('site/index', 'https');

還有另外一個方法?Url::to()?和 toRoute() 非常類似。這兩個方法的唯一區(qū)別在于,前者要求一個路由必須用數(shù)組來指定。 如果傳的參數(shù)為字符串,它將會被直接當(dāng)做 URL 。

Url::to()?的第一個參數(shù)可以是:

  • 數(shù)組:將會調(diào)用 toRoute() 來生成URL。比如:?['site/index'],?['post/index', 'page' => 2]?。 詳細用法請參考 toRoute() 。
  • 帶前導(dǎo)?@?的字符串:它將會被當(dāng)做別名, 對應(yīng)的別名字符串將會返回。
  • 空的字符串:當(dāng)前請求的 URL 將會被返回;
  • 普通的字符串:返回本身。

當(dāng)?$scheme?指定了(無論是字符串還是 true ),一個帶主機信息(通過 \yii\web\UrlManager::hostInfo 獲得) 的絕對 URL 將會被返回。如果?$url?已經(jīng)是絕對 URL 了, 它的協(xié)議信息將會被替換為指定的( https 或者 http )。

以下是一些使用示例:

// /index.php?r=site/indexecho Url::to(['site/index']);

// /index.php?r=site/index&src=ref1#nameecho 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 URLecho Url::to();

// /images/logo.gifecho Url::to('@web/images/logo.gif');

// images/logo.gifecho Url::to('images/logo.gif');

// http://www.example.com/images/logo.gifecho Url::to('@web/images/logo.gif', true);

// https://www.example.com/images/logo.gifecho Url::to('@web/images/logo.gif', 'https');

從2.0.3版本開始,你可以使用 yii\helpers\Url::current() 來創(chuàng)建一個基于當(dāng)前請求路由和 GET 參數(shù)的 URL。 你可以通過傳遞一個$params?給這個方法來添加或者刪除 GET 參數(shù)。 例如:

// assume $_GET = ['id' => 123, 'src' => 'google'], current route is "post/view"

// /index.php?r=post/view&id=123&src=googleecho Url::current();

// /index.php?r=post/view&id=123echo Url::current(['src' => null]);
// /index.php?r=post/view&id=100&src=googleecho Url::current(['id' => 100]);

記住 URLs

有時,你需要記住一個 URL 并在后續(xù)的請求處理中使用它。 你可以用以下方式達到這個目的:

// 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');

在后續(xù)的請求處理中,可以用如下方式獲得記住的 URL:

$url = Url::previous();
$productUrl = Url::previous('product');

檢查相對 URLs

你可以用如下代碼檢測一個 URL 是否是相對的(比如,包含主機信息部分)。

$isRelative?=?Url::isRelative('test/it');
?? ??: ?? ??: