Home >php教程 >PHP开发 >yii2.0 UrlManage link url rule analysis

yii2.0 UrlManage link url rule analysis

黄舟
黄舟Original
2017-01-03 09:25:111850browse


Url rules:

urlmanager is configured as an application component in [[yii aseApplication]]. You can access the instance through Yii: Yii::$app->urlManager

You can add an array to "components" under your application configuration, the example is as follows:

'urlManager' => [
'enablePrettyUrl' => true,
'rules' => [
// your rules go here
],
// ...
]

rules rule example:

[
'dashboard' => 'site/index',

&#39;POST <controller:w+>s&#39; => &#39;<controller>/create&#39;,
&#39;<controller:w+>s&#39; => &#39;<controller>/index&#39;,

&#39;PUT <controller:w+>/<id:d+>&#39; => &#39;<controller>/update&#39;,
&#39;DELETE <controller:w+>/<id:d+>&#39; => &#39;<controller>/delete&#39;,
&#39;<controller:w+>/<id:d+>&#39; => &#39;<controller>/view&#39;,
];

rules&#39; => [
// 为路由指定了一个别名,以 post 的复数形式来表示 post/index 路由
&#39;posts&#39; => &#39;post/index&#39;,

// id 是命名参数,post/100 形式的URL,其实是 post/view&id=100
&#39;post/<id:d+>&#39; => &#39;post/view&#39;,

// controller action 和 id 以命名参数形式出现
&#39;<controller:(post|comment)>/<id:d+>/<action:(create|update|delete)>&#39;=> &#39;<controller>/<action>&#39;,

// 包含了 HTTP 方法限定,仅限于DELETE方法
&#39;DELETE <controller:w+>/<id:d+>&#39; => &#39;<controller>/delete&#39;,

// 需要将 Web Server 配置成可以接收 *.digpage.com 域名的请求
&#39;http://<user:w+>.digpage.com/<lang:w+>/profile&#39; => &#39;user/profile&#39;,]

The above is the content of yii2.0 UrlManage link url rule analysis. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn