Denis Kulagin
Denis Kulagin

Reputation: 8906

Yii 1.1: static parameter in route

For the purpose of beautification I have a set of URL schemas like:

/alpha-action/...
/beta-action/...
/gamma-action/...
/delta-action/...

They are handled by the same controller and I wish by the same action like:

function actionAlphabet($letter, $param1)

What I want is to pass static parameter to action that would depend on the URL (syntax is made-up):

'alpha-action/<param1:.*>' => 'site/alphabet('alpha')',
'beta-action/<param1:.*>'  => 'site/alphabet('beta')',
'gamma-action/<param1:.*>' => 'site/alphabet('gamma')',
'delta-action/<param1:.*>' => 'site/alphabet('delta')'

Is it doable in Yii 1.1?

Upvotes: 0

Views: 124

Answers (1)

rob006
rob006

Reputation: 22174

I your case you can use params as a part of the pattern and use only one rule:

'<letter:\w+>-action/<param1:.*>' => 'site/alphabet',

But if you really want to create separate rules, you can use defaultParams property to specify default value for params not available in pattern:

'alpha-action/<param1:.*>' => ['site/alphabet', 'defaultParams' => ['letter' => 'alpha']],
'beta-action/<param1:.*>'  => ['site/alphabet', 'defaultParams' => ['letter' => 'beta']],
'gamma-action/<param1:.*>' => ['site/alphabet', 'defaultParams' => ['letter' => 'gamma']],
'delta-action/<param1:.*>' => ['site/alphabet', 'defaultParams' => ['letter' => 'delta']],

Upvotes: 1

Related Questions