I did this to use the xajax class from http://www.xajaxproject.org.
A normal use of the class:
$xajax = new xajax();
$xajax->registerFunction("send");
function send(){
$objResponse = new xajaxResponse();
$objResponse->addAlert('from Ajax call')
return $objResponse->getXML();
}
$xajax->processRequests();
Basicly the script call the function send() from a javascript. So i can execute php code asynchronously from a javascript called xajax_send() that will return a javascript: alert('from Ajax call').
Now, i use this code to encapsulate the xajax inside a class:
class foo{
public $dummy;
function __construct(){
$this->dummy = "Some value";
$this->meth_1(); //Set up the xajax class
}
function meth_1(){
global $interThis;
$interThis = $this;//Reference to the class
$xajax = new xajax();
$xajax->registerFunction("send");
function send(){
global $interThis // give acces to the class method and properties
$objResponse = new xajaxResponse();
$objResponse->addAlert($interThis->dummy.' from Ajax call')
return $objResponse->getXML();
}
$xajax->processRequests();
}
}
So, in this way i can call the xajax from inside a class, and every time I intance the foo class, i will have acces to use a javascript function called: xajax_send that will return a javascript alert('Some value from Ajax Call').
Im doing is a class to manage all the update, insert, delete for my database tables, using xajax. Now i can update, insert, delete rows sending javascript functions that manage that with out sending all the page, only calling the php function to update, insert or delete the row. Got me??