Topic: xajax+codeigniter

Is it possible to use xajax insider CodeIgniter framework?

Re: xajax+codeigniter

Yes it is possible:

1. Put the xajax folder in the CI libraries folder.

2. Rename xajax_core/ to xajax_core/xajax.php.

3. Open xajax.php and change class xajax to class Xajax.

4. Open the autoload.php in the config folder and make the libraries entry like this  like this:

    $autoload['libraries'] = array('xajax/xajax_core/xajax', ...any other libraries you use);

That should take care of it. In your controllers you can refer to $xajax with no further messing around.
Just configure the javascript URI and register your functions.

I extend the ci controller with My_Controller and all other controllers extend it.

I call processRequest in the constructor of the other controllers.

Here is My_Controller code:

class MY_Controller extends CI_Controller
    protected $resp;     //Local xajax response object
    public    $data;     //Local copy of the form data
    public    $xajax_js; //Xajax javascript.

    function __construct()
      //Redirect to the login page if the user is not logged
      //and the environment is production.

      if (defined('ENVIRONMENT') && ENVIRONMENT === 'production')
        if ($_SESSION['loggedin'] != true)

     * Local xajax setup
     * Register the dispatch function
     * create the response object and 
     * set the js URI.
     * xajax is autoloaded...
    function xajaxSetup()
      $this->xajax->configure('javascript URI', base_url().'application/libraries/xajax/');
      $this->xajax_js = $this->xajax->getJavascript();
      $this->resp = new xajaxResponse();

     * Standard xajax function dispatcher 
     * The only function registered with xajax...    
     * @param string $function_name - called function
     * @param mixed  $data - browser form data
     * All templates call xajax_dispatch('func',data);
     * Uses php 5's function variables feature.
     * Validate that the function exists and return it
     * passing in the data. Else alert the error.
    function dispatch($function_name, $data='')
      $this->data = $data;
      if (method_exists($this,$function_name)&& is_callable(array($this,$function_name)))
        return $this->$function_name($data);
        $resp = new xajaxResponse();
        $resp->alert("Invalid function name passed: $function_name");
        return resp;

Hope this helps...


If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.