Yii urlManager unlimited parameters
is there any way in yii to make the parameters unlimited
for example I have a module / admin /
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'admin/<controller:\w+>/<action:\w+>/<id:\d+>' => 'admin/<controller>/<action>',
'admin/<controller:\w+>/<action:\w+>'=>'admin/<controller>/<action>',
),
),
and inside the admin module I need each action to have unlimited parameters, for example:
/admin/anycontroller/anyaction/anything
/admin/anycontroller/anyaction/anything/anything2
/admin/anycontroller/anyaction/anything/anything2/anything3
/admin/anycontroller/anyaction/anything/anything2/anything3/anything4
... and so on
Should I define it one by one according to the rules? or is there a shortcut for this?
and how to catch it on controller action?
source to share
There is a shortcut:
'admin/<controller:\w+>/<action:\w+>/*'=>'admin/<controller>/<action>'
add the rule with /*
Since this is a more general rule that can capture many URLs, it would be better to have it at the bottom, or at least after any specific rules, like:
// ... other specific rules ...
'<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>', // specifically for id
// ... other specific rules ...
'admin/<controller:\w+>/<action:\w+>/*'=>'admin/<controller>/<action>'
In your case:
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'admin/<controller:\w+>/<action:\w+>/<id:\d+>' => 'admin/<controller>/<action>',
'admin/<controller:\w+>/<action:\w+>'=>'admin/<controller>/<action>',
'admin/<controller:\w+>/<action:\w+>/*'=>'admin/<controller>/<action>'
To catch it in action, simply do not provide any parameters for the action, for example:
public function actionSomething() {
// instead use $_GET
$params=$_GET;
}
But it should also work with the definition you already have: public function actionAnyAction($id=0,$type='',$type2='')
source to share