在cakephp中提取URL参数,URL以xml结尾


Extracting URL parameters in cakephp with URL that ends with xml

我想在cakephp中传递URL参数,URL以下面的xml结尾;

http://localhost/cp251/controller/api_get_info?page=1.xml

控制器函数是这样的;

public function api_get_info()
{
    if($this->RequestHandler->responseType() == 'xml')
    {
        //Problem is that the code never executes inside this if statement
        //Controller action
    }
}

问题是代码永远不会在if语句if($this->RequestHandler->responseType() == 'xml')中执行。但是,如果URL变为http://localhost/cp251/controller/api_get_info.xml,则代码将在if语句内执行。不幸的是,这不是我想要的,因为URL参数无法发送。

我如何通过URL参数在cakephp与URL以xml结尾?我使用的是cakephp 2.5.1

谢谢。

你的期望是错误的。

http://localhost/cp251/controller/api_get_info.xml

实际上是正确的格式。

http://localhost/cp251/controller/api_get_info?page=1.xml

不是(如果您希望查询字符串在使用XML扩展路由时工作)。

如果你想要附加查询字符串,总是在URL本身之后,例如

http://localhost/cp251/controller/api_get_info.xml?page=xxx&more=stuff