我想通过生成中提到的方法中的超链接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'])
我想像这样的网址 story/create/id/39/usr/11
但是它产生为
story/create?1%5Bid%5D=39&1%5Busr%5D=1
我已经启用了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.
如何做到这一点?
具有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'])
在urlManager中输入新规则:
rules' => array(
....
'story/create/<id:\d+>/<usr:\d+>' => 'story/create',
),
输出网址将如下所示:
story/create/39/11
并在控制器中:
public function actionCreate($id, $usr)
Yii2提供此参数。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句