keeg
keeg

Reputation: 3978

Hypen issue in urls in yii2

I have a simple action in my Controller:

public function actionReset( $key ) {
    echo $key;
    Yii::$app->end();
}

I am allowing this in my behaviors:

'rules'      => [
    [
        'actions' => [ 'message', 'activate', 'reset-request', 'reset' ],
        'allow'   => true,
    ],
],

it works fine. However as soon as I change the action to actionResetPassword and allow reset-password I get a 404 error. The funny thing is is that if I go to the url without the key in the address so:

/action/reset-password I get a 400 error that $key is missing.

but going to action/reset-password/somekeyhere I get 404 not found error.

EDIT:

This has to do with the hyphen in the action name:

--

WORKS:

rule: reset-password

action: actionResetpassword($key)

url tested: ~/action/resetpassword/somekeyhere

--

DOESN'T WORK:

rule: reset-password

action: actionResetPassword($key)

url tested: ~/action/reset-password/somekeyhere

--

DOESN'T WORK:

rule: reset-password

action: actionResetpassword($key)

url tested: ~/action/reset-password/somekeyhere

--

WORKS:

rule: reset-password

action: actionResetPassword()

url tested: ~/action/resetpassword

--

Upvotes: 0

Views: 205

Answers (2)

keeg
keeg

Reputation: 3978

It turns out

The issue was in the config of urlManager

Needed to fix the RegEx from:

'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>'

To:

'<controller:\w+>/<action:[\w-]+>/<id:\d+>' => '<controller>/<action>'

Upvotes: 0

Decimoseptimo
Decimoseptimo

Reputation: 103

No there isn't. There's some character limitation though but that's it. Whatever the issue cannot be that.

Upvotes: 2

Related Questions