use*_*282 10 clean-urls yii2 yii-url-manager
我想通过生成中提到的方法中的超链接 http://www.yiiframework.com/doc-2.0/guide-helper-html.html#hyperlinks这样
Html::a('<b>Register</b>',
['story/create', array('id' =>39,'usr'=>'11')],
['class' => 'profile-link'])
Run Code Online (Sandbox Code Playgroud)
我想得到网址 story/create/id/39/usr/11
但它正在产生
story/create?1%5Bid%5D=39&1%5Busr%5D=1
Run Code Online (Sandbox Code Playgroud)
我启用了yii2的干净网址功能
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
], also.
Run Code Online (Sandbox Code Playgroud)
如何实现这一目标?
vit*_*_74 25
随着生成url使用(见更多http://www.yiiframework.com/doc-2.0/guide-helper-url.html):
Html::a('<b>Register</b>',
['story/create', 'id' =>39,'usr'=>'11'],
['class' => 'profile-link'])
Run Code Online (Sandbox Code Playgroud)
在urlManager中输入新规则:
rules' => array(
....
'story/create/<id:\d+>/<usr:\d+>' => 'story/create',
),
Run Code Online (Sandbox Code Playgroud)
输出网址将是这样的:
story/create/39/11
Run Code Online (Sandbox Code Playgroud)
在控制器中:
public function actionCreate($id, $usr)
Run Code Online (Sandbox Code Playgroud)
并且Yii2提供此参数.
| 归档时间: |
|
| 查看次数: |
23160 次 |
| 最近记录: |