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

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

Url 助手

Url 幫助類(lèi)

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

獲得通用 URL

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

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

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

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

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

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

創(chuàng)建 URLs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

當(dāng)?$scheme?指定了(無(wú)論是字符串還是 true ),一個(gè)帶主機(jī)信息(通過(guò) \yii\web\UrlManager::hostInfo 獲得) 的絕對(duì) URL 將會(huì)被返回。如果?$url?已經(jīng)是絕對(duì) URL 了, 它的協(xié)議信息將會(huì)被替換為指定的( 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版本開(kāi)始,你可以使用 yii\helpers\Url::current() 來(lái)創(chuàng)建一個(gè)基于當(dāng)前請(qǐng)求路由和 GET 參數(shù)的 URL。 你可以通過(guò)傳遞一個(gè)$params?給這個(gè)方法來(lái)添加或者刪除 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

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

// 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ù)的請(qǐng)求處理中,可以用如下方式獲得記住的 URL:

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

檢查相對(duì) URLs

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

$isRelative?=?Url::isRelative('test/it');
Article précédent: Article suivant: