|
XAjAX, Smarty and CodeIgniter |
|
|
|
This is a short howto in how to setup XAjAX 0.5 in CodeIgniter 1.7.1 & Smarty 2.6.22.
- 1: Follow in how to setup smarty as a template engine in CodeIgniter.
- 2: Download XAjAX and extract it.
- 3: Copy the folder xajax_core into /system/application/libraries
- 4: Create a library class The_xajax.php:
if (!defined('BASEPATH')) exit('No direct script access allowed');
require "xajax_core/xajax.inc.php";
class The_xajax extends xajax
{
function The_xajax()
{
$this->xajax();
}
function loadJavascriptForSmarty($theSmarty)
{
$theSmarty->assign( 'the_xajax_js', $this->getJavascript(base_url()) );
}
} // END class The_xajax
- 5: The controller hello.php:
load->library('the_xajax');
$this->the_xajax->registerFunction(array('test_function',&$this,'test_function'));
$this->the_xajax->loadJavascriptForSmarty($this->mysmarty);
$this->the_xajax->processRequest();
}
function index() {
$this->mysmarty->view( 'hello' );
}
function test_function()
{
$objResponse = new xajaxResponse();
$objResponse->Assign("SomeElementId","innerHTML", "Hello world";
return $objResponse;
}
}
- 6: And within the view template hello.tpl add to the header:
{$my_xajax_js}
And within the body:
<div id="SomeElementId">TEST</div>
<input type="button" value="test" onclick="xajax_test_function(2);">
Error using $config['global_xss_filtering'] = TRUE; together with XAjAX
The problem is that xss_filtering replaces <![CDATA[ with <![CDATA[.
To prevent this behavior you have to deactive this within the $never_allowed_str. To do so, create a file called My_Input.php within /system/application/libraries:
class My_Input extends CI_Input
{
var $never_allowed_str = array(
'document.cookie' => '[removed]',
'document.write' => '[removed]',
'.parentNode' => '[removed]',
'.innerHTML' => '[removed]',
'window.location' => '[removed]',
'-moz-binding' => '[removed]',
'' => '-->',
#'<![CDATA[' => '<![CDATA['
);
}
For sure, you weak the security by doing so. |