Ruslan Polutsygan
Ruslan Polutsygan

Reputation: 4461

yii url manager. urls in path format

I've been developing web application based on Yii framework.

I've faced with troubles on trying to make sef urls.

What I have:

  1. config is set up.

    'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName'=>false, 'rules'=>array( // rules go here ) )

  2. This is code which is used for tesing:

echo $this->createUrl('site/test', array('help'=>'me')

$this - is controller.

If I'm living 'rules' array in config empty I'm getting this /site/test/help/me. I expected this.

If

'rules'=>array(
    '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
)

I'm getting /site/test?help=me which is also expected.

But if

'rules'=>array(
    '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
    '<controller:\w+>/<action:\w+>/<help:\w+>' => '<controller>/<action>/<help>',
)

I'm still getting /site/test?help=me. I expected to see /site/test/me

Could anyone help me?

Thanks in advance.

Upvotes: 3

Views: 5730

Answers (1)

Marcin K
Marcin K

Reputation: 76

Change the order of rules and remove <help>. It will be automatically added to action. So your rules should look like this:

'<controller:\w+>/<action:\w+>/<help:\w+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',

Order of rules matters. You need to put the most detailed one first.

Regards

Upvotes: 6

Related Questions