Yii 框架获取GET参数时为什么会带入pathinfo

技术问题 · phpworkerman · 于 3年前 发布 · 1152 次阅读

程序当中在处理一个GET请求,打印参数后发现不知有问号后的参数,还有问号前的pathinfo也当作参数获取了,本地测试正常,线上会获取pathinfo,不知道是哪里配置的有问题,望解答。

/*请求URL
http://api.xxxx.com/v1/kkk/order?order_amount=999&currency=CNY
*/

$param = Yii::$app->request->get();
print_r($param);
//输出
Array
(
    [/v1/kkk/order] => 
    [order_amount] => 999
    [currency] => CNY
)

共收到 3 条回复
Fecmall#13年前 0 个赞

测试了一下:

public function actionTest()
    {
        // http://fecyo.fecshop.com/cms/home/test?order_amount=999&currency=CNY
        $param = Yii::$app->request->get();
        print_r($param);
        exit;
    }

打印:

array(2) { ["order_amount"]=> string(3) "999" ["currency"]=> string(3) "CNY" }

没有问题,你是不是yii2的参数配置有问题?

再次测试时没有用 Yii 封装的请求类,直接用 $_GET 获取参数后,发现依然会带 pathinfo,排除了框架的问题,查到是 nginx 的伪静态配置造成的,代码如下:

if (!-d $request_filename){
	set $rule_0 1$rule_0;
}
if (!-f $request_filename){
	set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
	rewrite ^/(.*)$ /index.php?/$1 last;
}
Fecmall#33年前 0 个赞

@phpworkerman #2楼

多谢分享,赞+1

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics