使用 clean urls 在 yii2 的超链接中传递多个参数,Html::a() 不会生成 clean url
Passing multiple parameters in a hyperlink in yii2 with clean urls, Html::a() doesnt generate clean url
我正在尝试通过中提到的方法生成超级 link
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'])
我想url喜欢story/create/id/39/usr/11
但它正在生成
story/create?1%5Bid%5D=39&1%5Busr%5D=1
我启用了 yii2 的干净 url 功能,例如
'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'])
在url管理员中输入新规则:
rules' => array(
....
'story/create/<id:\d+>/<usr:\d+>' => 'story/create',
),
输出url会是这样的:
story/create/39/11
在控制器中:
public function actionCreate($id, $usr)
而Yii2提供了这个参数。
动态创建Url
Html::a('<b>Register</b>',
['story/create', 'id' =>39,'usr'=>'11'],
['class' => 'profile-link'])
在url管理器配置规则中:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>/<usr:\d+>' => '<controller>/<action>',
],
],
输出url将是这样的:
story/create/39/11
另一个有用的方法:
在您的
中写入 url 经理规则
'rules'=>array('/controller/action/<limit>/<offset>'=>'/controller/action/'),
可以在 url controller/action/100/20
中访问
我正在尝试通过中提到的方法生成超级 link 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'])
我想url喜欢story/create/id/39/usr/11
但它正在生成
story/create?1%5Bid%5D=39&1%5Busr%5D=1
我启用了 yii2 的干净 url 功能,例如
'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'])
在url管理员中输入新规则:
rules' => array(
....
'story/create/<id:\d+>/<usr:\d+>' => 'story/create',
),
输出url会是这样的:
story/create/39/11
在控制器中:
public function actionCreate($id, $usr)
而Yii2提供了这个参数。
动态创建Url
Html::a('<b>Register</b>',
['story/create', 'id' =>39,'usr'=>'11'],
['class' => 'profile-link'])
在url管理器配置规则中:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>/<usr:\d+>' => '<controller>/<action>',
],
],
输出url将是这样的:
story/create/39/11
另一个有用的方法:
在您的
中写入 url 经理规则'rules'=>array('/controller/action/<limit>/<offset>'=>'/controller/action/'),
可以在 url controller/action/100/20
中访问