Search code examples
xmlcakephprequesthandlerjson-view

set RequestHandler to use XmlView by default


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.

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'); 
        }
    }