cakeHP在GET请求中返回空参数



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

我使用的是cakeHPP3,在cakeHP2.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: CakeNetworkRequest 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] => CakeNetworkSession Object
(
[_engine:protected] => 
[_started:protected] => 1
[_lifetime:protected] => 1440
[_isCli:protected] => 
)
)

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

经过更多的调试

我发现这个问题与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

我的重写规则是根据cakeHP书上的建议:

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

有没有人有cakeHP的重写规则,或者有其他地方可以定义它?

最后总是简单的

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

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

最新更新