Answer the question
In order to leave comments, you need to log in
Yii2 UrlManager - why are optional parameters not substituted?
I am using the Yii2 framework.
The configuration has a rule for UrlManager:
....
'components' => [
...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
...
[
'pattern' => '<some-param>/some-page',
'route' => 'some/route',
'defaults' => ['some-param' => 'default-value']
],
...
]
],
...
]
....
echo Html::a('Some page', ['some/route']);
Answer the question
In order to leave comments, you need to log in
1. Perhaps there is a rule that works instead, you need to change their order in this case. Show the full list of rules or move it yourself.
2. This is exactly how it should work
'rules' => [
'<someparam>/some-page' => 'some/route',
],
public function actionRoute($someparam = 'default_value'){
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question