很快,我将在 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 接受字母数字参数。
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>'
应该这样
关于php - URL 不接受字母数字参数 - Yii2-app-basic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32988996/