如何更改yii2的url结构(从controller / view?id = to view / id)

时间:2016-09-07 04:57:51

标签: yii2

如何更改yii2的网址结构(从控制器/视图?id = controller / view / id

1 个答案:

答案 0 :(得分:1)

似乎您已经启用了漂亮的网址规则,因此您需要添加网址规则。将其添加到您的应用配置:

return [
    'components' => [
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => false,
            'rules' => [
                'controller/view/<id:\d+>' => 'controller/view',
            ],
        ],
    ],
]
  

我希望网址像:test.advanced.loc/member/profile/view/c_id/1。目前,它是test.advanced.loc/member/profile/view?c_id=1

在这种情况下,网址规则应为:

'member/profile/view/c_id/<c_id:\d+>' => 'member/profile/view',

更多信息和示例可在offical docs中找到。