Answer the question
In order to leave comments, you need to log in
Yii. How to make rule an optional parameter?
There is a rule:
'urlManager'=>array(
'urlFormat' => 'path',
'showScriptName'=>false,
'rules'=>array(
'page/<id:\d+>/<alias:.*>' => 'page/index/',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
<platform:.*>
, but it may not be there. 'page/<id:\d+>/<alias:.*>/<platform:.*>' => 'page/index/',
Answer the question
In order to leave comments, you need to log in
Maybe a crutch of course, but it turned out to solve the problem without setting an optional parameter. In 'rules' listed what links can be:
'rules'=>array(
'page/<id:\d+>/<alias:.*>/<platform:.*>' => 'page/index/',
'page/<id:\d+>/<alias:.*>' => 'page/index/',
'page/<id:\d+>' => 'page/index/',
'page' => 'page/index/',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
Try to use
/**
* @var array the default GET parameters (name=>value) that this rule provides.
* When this rule is used to parse the incoming request, the values declared in this property
* will be injected into $_GET.
*/
public $defaultParams=array();
[
'route' => 'page/index',
'pattern' =>'page/<id:\d+>/<alias:.*>/<platform:.*>',
'defaultParams => [
'platform' => 'some platform'
]
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question