CodeIgniterでxajaxを利用する方法

CodeIgniter 2.0.3にXajax 0.6 beta1をいれたときのメモ。


ダウンロード

下記のサイトから「Xajax 0.6 beta1」をダウンロード。
http://www.xajax-project.org/en/home/


CodeIgniterへコピー

xajax_coreをxajaxへリネームしてapplication/third_party内へコピー。
xajax_jsをjs内へコピー。


ファイルの修正

xajax_jsの前に「js/」を追加

application/third_party/xajax/xajax.inc.php
    /*
        Function: autoCompressJavascript
 
        Creates a new xajax_core, xajax_debug, etc... file out of the
        _uncompressed file with a similar name.  This strips out the
        comments and extraneous whitespace so the file is as small as
        possible without modifying the function of the code.
 
        Parameters:
 
        sJsFullFilename - (string):  The relative path and name of the file
            to be compressed.
        bAlways - (boolean):  Compress the file, even if it already exists.
    */
    public function autoCompressJavascript($sJsFullFilename=NULL, $bAlways=false)
    {
        $sJsFile = 'js/xajax_js/xajax_core.js';
 
        if ($sJsFullFilename) {
            $realJsFile = $sJsFullFilename;
        }
application/third_party/xajax/plugin_layer/xajaxDefaultIncludePlugin.inc.php
    /*
        Function: printJavascriptInclude
 
        See <xajaxIncludeClientScriptPlugin::getJavascriptInclude>
    */
    public function printJavascriptInclude()
    {
        $aJsFiles = $this->aJsFiles;
        $sJsURI = $this->sJsURI;
 
        if (0 == count($aJsFiles)) {
            $aJsFiles[] = array($this->_getScriptFilename('js/xajax_js/xajax_core.js'), 'xajax');
 
            if (true === $this->bDebug)
                $aJsFiles[] = array($this->_getScriptFilename('js/xajax_js/xajax_debug.js'), 'xajax.debug');
 
            if (true === $this->bVerboseDebug)
                $aJsFiles[] = array($this->_getScriptFilename('js/xajax_js/xajax_verbose.js'), 'xajax.debug.verbose');
 
            if (null !== $this->sLanguage)
                $aJsFiles[] = array($this->_getScriptFilename('js/xajax_js/xajax_lang_' . $this->sLanguage . '.js'), 'xajax');
        }

サンプルコード

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Xajax_test extends CI_Controller {
 
    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        include(APPPATH.'third_party/xajax/xajax.inc'.EXT);
        $this->xajax = new xajax(base_url());
        $this->xajax->register(XAJAX_FUNCTION, array('test_function', $this, 'test_function') );
        $this->xajax->processRequest();
    }
 
    public function index() {
        echo $this->xajax->getJavascript();
        echo '<div id="xajax_div"></div><input type="button" value="test" onclick="xajax_test_function(); return true;">';
    }
 
    function test_function() {
        $objResponse = new xajaxResponse();
        $objResponse->assign('xajax_div', 'innerHTML', 'xajax test');
        return $objResponse;
    }
}

testボタン押したあとに「xajax test」と表示されたら成功!


関連記事

コメントの投稿

非公開コメント

最新記事
カテゴリ
スポンサード
スポンサード
月別アーカイブ
RSSリンクの表示
QRコード
QR