3

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.

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.