DBの内容をxml形式もしくはjson形式で返す
root.phpにxmlとjsonを扱えるよう宣言
Router::parseExtensions('json', 'xml');
欲しいデータのコントローラのコンポーネントに追加
public $components = array('RequestHandler');
データを吐き出すfunctionを用意
public function index() {
$this->モデル名->recursive = 0;
$this->set('chirashiBoths', $this->Paginator->paginate());
$this->set('data', $this->モデル名->find('all'));
}
ビューを用意
// View/コントローラー名/xml/index.ctp
// View/コントローラー名/json/index.ctp
// コントローラー名のディレクトリにxmlとjsonと言うディレクトリを作成し、そこにテンプレートファイルを用意
// xmlの場合
$items = array('items'=> array('item'=> $data));
$xml = Xml::fromArray(array('response'=>$items));
echo $xml->asXML();
// jsonの場合
$items = array('items'=> array('item'=> $data));
echo json_encode(array('response'=>$items),JSON_UNESCAPED_UNICODE);