简体   繁体   中英

Extracting URL parameters in cakephp with URL that ends with xml

I would like to pass URL parameters in cakephp with URL that ends with xml like below;

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

The controller function looks like this;

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

    }
}

The problem is that the code never executes inside the if statement if($this->RequestHandler->responseType() == 'xml') . However, if the URL becomes http://localhost/cp251/controller/api_get_info.xml , then the code will execute inside the if statement. Unfortunately, this is not what I want because the URL parameters cannot be sent.

How can I pass URL parameters in cakephp with URL that ends with xml? I am using cakephp 2.5.1

Thank you.

Your expectation is flawed.

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

actually IS the correct format.

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

is not (if you want query strings to work while using xml extension routing).

If you want to append query strings, always do that after the URL itself, eg

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM