Question

I'm using the Xml/Json views for an API.

Going to '/Api.json' or '/Api.xml' works fine, but I'd like it to default to the XmlView when posting to '/Api'

What's the most simple/best way get this done?

  • Edit: As Jelmer mentioned, just doing '$this->layout = "xml"' does the trick - they should mention this in the documentation.
Was it helpful?

Solution

The real trick was this one liner, had to look at the api documentation and try a couple of things:

public function beforeRender() {
    if(empty($this->RequestHandler->request->params['ext'])) {
        $this->RequestHandler->renderAs($this, 'xml'); 
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top