URL not accepting alpha numeric parameter - Yii2-app-basic

As soon as I pass 41 at the URL. confirm.php fingerprints 41.

http: // localhost / yii2-app-basic / web / site / confirm / 41

But, when I pass "cfeb70c4c627167ee56d6e09b591a3ee" or "41a" to the URL,

http: // localhost / yii2-app-basic / web / site / confirm / 41a

error displayed

NOT FOUND (# 404)
Page not found.

The above error occurred while the web server was processing your request. Please contact us if you think this is a server error. Thanks.

I want to send a verification ID to the user in order to verify my account. That is why the random number "cfeb70c4c627167ee56d6e09b591a3ee" is transmitted.

So what can I do to make the url accept an alpha numeric parameter.

config /web.php

'urlManager' => [ 'showScriptName' => false, 'enablePrettyUrl' => true, 'enableStrictParsing' => false, 'rules' => [ '<controller>/<action>/<id:\d+>' => '<controller>/<action>' ], ], 

SiteController.php

 public function actionConfirm($id) { $id = Yii::$app->request->get('id'); $this->view->params['customParam'] = $id; return $this->render("confirm",array("id"=>$id)); } 
+3
source share
2 answers

Change this line

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

to that

 '<controller>/<action>/<id:[a-z0-9]+>' => '<controller>/<action>' 

It should do it

+4
source

The current rule states that id is a number ( \d+ ), so it does not work in your examples. Instead of changing the current rule, I would add it specifically for this case:

 'rules' => [ 'site/confirm/<id:\w+>' => 'site/confirm', '<controller>/<action>/<id:\d+>' => '<controller>/<action>' ], 
+2
source

Source: https://habr.com/ru/post/1238619/


All Articles