如何在Yii2中启用多语言的干净网址

时间:2017-10-04 13:09:03

标签: php yii2 clean-urls

如何在Yii2中使用多种语言启用 clean-urls

in - English
https://www.myfolder.com/en/restaurant/Bez_Gwiazdek-Warsaw

in - French
https://www.myfolder.com/fr/restaurant/Bez_Gwiazdek-Varsovie

in - Polish
https://www.myfolder.com/pl/Restauracja/Bez_Gwiazdek-Warszawa 

1 个答案:

答案 0 :(得分:0)

请查看此存储库https://github.com/codemix/yii2-localeurls#example-language-selection-widget

您需要更新urlManager配置,例如

[
    'language' => 'en',
    'components' => [
        'urlManager' => [
            'class' => 'codemix\localeurls\UrlManager',
            'languages' => ['en','pl','fr'],
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '<controller:\w+>/<action:\w+>/<slug:[A-Za-z0-9 -_.]+>' => '<controller>/<action>',
            ],
        ],
...
]