如何在Yii2中为3个模块编写url模式?

时间:2017-05-16 11:55:53

标签: yii2 url-routing url-pattern

我的网址:

1)工作

http:// yii2store / backend / web / en-us / seller / catalog / products

en-us / seller / catalog / products

[
'name' => 'lang_country_module',
'pattern' => '<lang:\w+>-<country:\w+>/<module>/<controller>/<action>',
'route' => '<module>/<controller>/<action>',
],

2)它没有工作

http:// yii2store / backend / web / en-us / seller / catalog / attributes / productsattributeslogisticsinfo

en-us: -

卖家/目录/属性:3个模块

productsattributeslogisticsinfo:controller

我的完整规则:

[
                // Lang rule
                'name' => 'lang_country',
                'pattern' => '<lang:\w+>-<country:\w+>/<controller>/<action>', 
                'route' => '<controller>/<action>',

            ],
            [
                'name' => 'lang_country_module',
                'pattern' => '<lang:\w+>-<country:\w+>/<module>/<controller>/<action>',
                'route' => '<module>/<controller>/<action>',
            ],
            [
                'name' => 'lang_country_module2',
                'pattern' => '<lang:\w+>-<country:\w+>/(?J)<module>/<controller>/<action>',
                'route' => '<module>/<controller>/<action>',
            ],
            [
                'name' => 'lang_country_module_only',
                'pattern' => '<lang:\w+>-<country:\w+>/<module>',
                'route' => '<module>',
            ],
            [

                'name' => 'lang_country_module_only2',
                'pattern' => '<lang:\w+>-<country:\w+>/(?J)<module>',
                'route' => '<module>',
            ],

我不喜欢

http://yii2store/backend/web/seller/catalog/attributes/attributesproducts?lang=en&country=us

我想要

http://yii2store/backend/web/en-us/seller/catalog/attributes/attributesproducts

我的

1 个答案:

答案 0 :(得分:0)

对于lang param我建议使用codemix / yii2-localeurls。有了这个,你可以忘记你的模式<lang:\w+>