只是這樣你則params的默認值配置規則:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
[
'pattern' => 'test/<param1:\d+>/<param2:\d+>/<param3:\d+>/<param4:\d+>/<slug>',
'route' => 'site/test',
'defaults' => [
'param1' => null,
'param2' => null,
'param3' => null,
'param4' => null,
]
]
]
],
所有參數,具有默認值不是必需的,可以跳過。這裏是行爲的例子:
http://yii2.local/test/slug:
skipped.array (size=5)
'param1' => null
'param2' => null
'param3' => null
'param4' => null
'slug' => string 'slug' (length=4)
http://yii2.local/test/2/4/slug
array (size=5)
'param1' => string '2' (length=1)
'param2' => string '4' (length=1)
'param3' => null
'param4' => null
'slug' => string 'slug' (length=4)
這看起來不錯,還會再來一旦實施,讓你知道它的工作。 – ahervin
@ahervin對你來說成功了嗎? – SilverFire
我已經注意到在實施時更新此答案的任務。對延遲抱歉。 – ahervin