dqst96444
2015-10-08 20:02
浏览 18
已采纳

没有正确创建多个参数的网址

I can't seem to get pretty urls to be generated properly. My frontend config is as follows:

'urlManager' => [
    'enablePrettyUrl' => true,
    'showScriptName' => false,
    'rules' => [
        'item/<id:\d+>/<slug>' => 'item/view',
        'category/<id:\d+>/<slug>' => 'category/view',
        '<controller:\w+>/<id:\d+>' => '<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
        '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
    ]
],

The following url array:

['item/view', 'id' => 4, 'slug' => 'shark-chomp-socks']

generates the url http://example.com/item/4?slug=shark-chomp-socks instead of http://example.com/item/4/shark-chomp-socks.

If I manually type in the expected url (http://example.com/item/4/shark-chomp-socks), the url resolves correctly without any errors.

How can I get it to generate the url properly?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题