Hyml :: a()在yii2中的超链接中使用干净的URL传递多个参数,但不会生成干净的URL [英] Passing multiple parameters in a hyperlink in yii2 with clean urls, Html::a() doesnt generate clean url
本文介绍了Hyml :: a()在yii2中的超链接中使用干净的URL传递多个参数,但不会生成干净的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过中提到的方法生成超链接 http://www.yiiframework.com/doc-2.0/guide-helper-html. html#hyperlinks 这样
I am trying to generate a hyper link by the method mentioned in http://www.yiiframework.com/doc-2.0/guide-helper-html.html#hyperlinks like this
Html::a('<b>Register</b>',
['story/create', array('id' =>39,'usr'=>'11')],
['class' => 'profile-link'])
我想获取类似story/create/id/39/usr/11
但是它生成为
story/create?1%5Bid%5D=39&1%5Busr%5D=1
我已经启用了yii2的干净url功能,例如
I have enabled the clean url functionality of yii2 like
'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.
这如何实现?
推荐答案
With generate url
use like that (see more 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'])
在urlManager中输入新规则:
In urlManager input new rule:
rules' => array(
....
'story/create/<id:\d+>/<usr:\d+>' => 'story/create',
),
输出网址如下:
story/create/39/11
在控制器中:
public function actionCreate($id, $usr)
Yii2提供了此参数.
And Yii2 provide this parameter.
这篇关于Hyml :: a()在yii2中的超链接中使用干净的URL传递多个参数,但不会生成干净的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文