'urlManager' => [ 'showScriptName' => false, 'enablePrettyUrl' => true, 'rules' => [ 'about' => 'site/about', ] ],
<ParamName:RegExp>, 這裡 ?
ParamName ?引數名稱
RegExp ? 可選的正規表示式用於匹配引數值
[ 'articles/<year:\d{4}>/<category>' => 'article/index', 'articles' => 'article/index', 'article/<id:\d+>' => 'article/view', ]
Url::to(['article/index']) 建立成 /index.php/articles
Url::to(['article/index', 'year' => 2016, 'category' => 'php']) 建立成 /index.php/articles/2016/php
Url::to(['article/view', 'id' => 100]) 建立成/index.php/article/100
Url::to(['article/view', 'id' => 100, 'source' => 'ad']) 建立成/index.php/article/100?source=ad
Url::to(['article/index', 'category' => 'php']) 建立成 /index.php/article/index?category=php
在urlManager的使用上,用得最多的組態項就是:
在 UrlManager::init() 初始化過程中,可以發現 urlManager 使用了應用所提供的快取元件(有果有的話), 對所有路由規則的範例進行快取。
yii\web\UrlManager::$suffix'urlManager' => [ 'showScriptName' => false, 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'suffix' => '.html' ],