0

我正在为 API 使用 Xml/Json 视图。

转到“/Api.json”或“/Api.xml”工作正常,但我希望它在发布到“/Api”时默认为 XmlView

完成这项工作的最简单/最好的方法是什么?

  • 编辑:正如 Jelmer 提到的,只需执行 '$this->layout = "xml"' 就可以了——他们应该在文档中提到这一点。
4

1 回答 1

0

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'); 
    }
}
于 2013-07-03T08:57:16.937 回答