自分のためのメモで雑なポストになることを予め謝っておきます。ごめんなさい。
CakePHP1.3系の話です。
RequestHandlerコンポーネントを使用します。
Ajax専用で呼び出す場合の書き方
/**
* Ajaxで呼び出すアクション(method)
**/
function hoge_ajax() {
if (!$this->RequestHandler->isAjax()) {
$this->cakeError("error404");
exit;
}
Configure::write("debug", 0);
$this->layout = "ajax";
// 処理処理
}
Ajaxと通常呼び出しの両方に対応するアクション
function hoge() {
if ($this->RequestHandler->isAjax()) {
Configure::write("debug", 0);
$this->layout = "ajax";
}
// ↓処理
// Viewが異なる場合は$this->renderの分岐を書く
}
僕のコピペ用です。