cakePHP 在 GET 请求中返回空参数

cakePHP returning empty parameters on the GET request

我在读取 GET 请求的参数时遇到问题: www.example.com/users/checkusername?用户名=e

我正在使用 cakePHP 3,在 cakePHP 2.6.4 上运行没有问题。

通过这些方式我得到了一个空结果:

$this->log($this->request->query['username']);
$this->log( $this->params['url']);

结果:

2015-04-28 17:28:22 Error:
2015-04-28 17:28:22 Error:

但是,检查整个请求可以验证参数是否存在

$this->log($this->request);

这些是输出:

2015-04-28 17:28:22 Error: Cake\Network\Request Object
(
    [params] => Array
        (
            [plugin] => 
            [controller] => Users
            [action] => checkusername
            [_ext] => 
            [pass] => Array
                (
                )

            [_Token] => Array
                (
                    [unlockedFields] => Array
                        (
                        )

                )

        )

    [data] => Array
        (
        )

    [query] => Array
        (
        )

    [cookies] => Array
        (
            [CAKEPHP] => u8lgs1cup81331lka3a90jidd4
        )

    [_environment:protected] => Array
        (
        **removed**
            [REQUEST_METHOD] => GET
            [REQUEST_URI] => /users/checkusername?username=e
            [SCRIPT_NAME] => /index.php
        **removed**
        )

    [url] => users/checkusername
    [base] => 
    [webroot] => /
    [here] => /users/checkusername
    [trustProxy] => 
    [_detectorCache:protected] => Array
        (
            [post] => 
            [put] => 
        )

    [_input:protected] => 
    [_session:protected] => Cake\Network\Session Object
        (
            [_engine:protected] => 
            [_started:protected] => 1
            [_lifetime:protected] => 1440
            [_isCli:protected] => 
        )

)

有人知道如何读取这个参数吗?

After more debugging

我发现问题与 Hiawatha 重写规则有关。我只是添加

<?php echo phpinfo(); ?>

在文件开头 /webroot/index.php.

当我使用:https://www.example.com/?code=123

有效,我得到了这些结果

PHP Variables            Variable Value
_REQUEST["code"]           123
_GET["code"]               123
_SERVER["REQUEST_URI"]     /?code=123
_SERVER["SCRIPT_NAME"]     /index.php

但是当我尝试时:https://www.example.com/users/confirm?code=123

变量没有显示。

_SERVER["REQUEST_URI"]     /users/confirm/?code=123
_SERVER["SCRIPT_NAME"]     /index.php

我的重写规则是根据cakePHP书上的推荐:

UrlToolkit {
   ToolkitID = cakephp
   RequestURI exists Return
   Match .* Rewrite /index.php
}

有没有人有cakePHP的重写规则或者有别的地方可以定义它?

最后总是很简单

这是 CakePHP 在 Hiawatha 服务器上接收 GET 请求的重写规则

UrlToolkit {
   ToolkitID = cakephp
   RequestURI exists Return
   Match .*\?(.*) Rewrite /index.php?
   Match .* Rewrite /index.php
}