编程语言
首页 > 编程语言> > php – 不接受字母数字参数的URL – Yii2-app-basic

php – 不接受字母数字参数的URL – Yii2-app-basic

作者:互联网

很快,我在URL中传递41. confirm.php打印41.

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

但是,当我在URL中传递“cfeb70c4c627167ee56d6e09b591a3ee”或“41a”时,

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

它显示错误

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. Thank you.

我想向用户发送确认ID以确认其帐户.
这就是随机号码“cfeb70c4c627167ee56d6e09b591a3ee”正在通过的原因.

那么,我该怎么做才能使URL接受字母数字参数.

配置/ 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));
}

解决方法:

改变这一行

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

对此

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

应该这样做

标签:yii2-basic-app,php,yii2,url-routing
来源: https://codeday.me/bug/20190824/1707976.html