【发布时间】:2015-04-28 18:06:20
【问题描述】:
我在 Yii2 配置文件中设置了 enablePrettyUrl 到 true 和 showScriptName 到 false。我的默认控制器名为public。
我也有这两条规则:
[
'pattern' => '<category_id:\w{6}>/<product_id:\w{6}>/<slug:.*?$>/',
'route' => 'public/product',
'defaults' => [
'seo_url' => ''
]
],
[
'pattern' => 'public/<category_id:\d{6}>/<product_id:\d{6}>/<slug:.*?$>/',
'route' => 'public/product',
'defaults' => [
'seo_url' => ''
]
]
允许我使用以下 URL 访问我的页面中的产品:
http://example.com/123456/987654/this-is-a-prodduct-example-url
现在,我希望这样:
Url::to(["/product", "category_id" => 123456, "product_id" => 98765, "slug" => "this-is-a-product-example-url"]);
形成任何一个:
/123456/987654/this-is-a-product-example-url
/product/123456/987654/this-is-a-product-example-url
/public/product/123456/987654/this-is-a-product-example-url
但我却得到了这个:
/product/?category_id=123456&product_id=987654&slug=this-is-a-product-example-url
为什么会这样,我该如何解决?
【问题讨论】:
-
也许是
['public/product', ...]而不是['product', ...]?