記載された情報が古くなっている可能性がございますので十分ご注意ください。
最新版のCodeIgniter から XAjax を利用してみます。
環境は以下の通りです。
CodeIgniter 2.01
XAjax 0.5 standard
コントローラのコンストラクタに以下の記述
require_once(APPPATH.'libraries/xajax_core/xajax.inc'.EXT);
$this->xajax = new xajax();
$this->xajax->register(XAJAX_FUNCTION,array(&$this, "test_func")); <strong>※ここの記述がポイント</strong>
$this->xajax->processRequest();
$this->xajax->configure('debug', true);
コントローラにXAjax用の関数を以下のように追記
public function test_func($text)
{
$objResponse = new xajaxResponse();
$objResponse->assign('div1', 'innerHTML', $text);
return $objResponse;
}
ビュー内に以下の関係するコードを追加
<?php $this->xajax->printJavaScript("./"); ?>
<button onclick='xajax_test_func("こんにちは");' >Click Me</button>
<div id="div1"> </div>
「※ここの記述がポイント」の説明
XAjaxのバージョンによって、「register」と「registerFunction」(旧書式)があるが推奨は「register」を使いましょう。
コントローラ内でXAjax用の関数は「$this->test_func」のように呼び出す。
そのため、「array(&$this, “test_func”)」に記述している。
もし、仮にビュー内にXAjax用の関数を記述していれば、直接「”test_func”」で呼び出すことができるのだから、「register(XAJAX_FUNCTION, “test_func”)」このようになる。









