URL 不接受字母数字参数 - Yii2-app-basic [英] URL not accepting alpha numeric parameter - Yii2-app-basic
问题描述
很快,我将在 URL 中传递 41.Confirm.php 打印 41.
As soon, i'm passing 41 in URL. confirm.php prints 41.
http://localhost/yii2-app-basic/web/site/确认/41
但是,当我在 URL 中传递cfeb70c4c627167ee56d6e09b591a3ee"或41a"时,
But, when i pass "cfeb70c4c627167ee56d6e09b591a3ee" or "41a" in URL,
http://localhost/yii2-app-basic/web/site/confirm/41a
显示错误
未找到 (#404)
找不到网页.
NOT FOUND (#404)
Page not found.
上述错误发生在 Web 服务器处理您的请求时.如果您认为,请联系我们这是服务器错误.谢谢.
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"被传递的原因.
I want to send confirmation id to user to confirm their account. That's why random number "cfeb70c4c627167ee56d6e09b591a3ee" is being passed.
那么,我该怎么做才能让 URL 接受字母数字参数.
So, what can i do to make URL accept 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));
}
推荐答案
更改此行
'<controller>/<action>/<id:\d+>' => '<controller>/<action>'
到这里
'<controller>/<action>/<id:[a-z0-9]+>' => '<controller>/<action>'
应该可以
这篇关于URL 不接受字母数字参数 - Yii2-app-basic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!