Upgrading from xajax 0.2 to xajax 0.5






Upgrading from xajax 0.2 to xajax 0.5

(Redirected from 0.5 Upgrade Info)

At this point, it is recommended that you follow the procedure laid out below, when migrating from xajax 0.2.x to xajax 0.5

Contents

[edit] Update to the latest version of xajax 0.2

The first step is to upgrade your site to the latest version of xajax 0.2, which is xajax 0.2.5 This will give you the opportunity to then update your xajax calls a little at a time without experiencing php errors along the way. If you jump directly to xajax 0.5, you will be forced to update to the latest syntax all at once, which would be a problem for a large project. (For small projects it might be ok to jump directly to xajax 0.5)

[edit] Update to the new syntax

[edit] Response Commands

xajaxResponse has been refactored to allow future support for other data transport methods. Currently, response commands are stored in an array; the array is converted to XML just before the response is sent. Previously, the XML was built as commands were added to the response, via string concatination.

[edit] Method Renaming

Please Note: You can use all of the old methods by instanciating new legacyXajax() instead of new xajax() and new legacyXajaxResponse() instead of xajaxResponse().


xajax Methods

xajax->processRequests() has become xajax->processRequest()

All boolean settings such as xajax->debugOn(); and xajax->outputEntitiesOn(); have become xajax->setFlag('debug',true) and xajax->setFlag('outputEntities',true); xajax->setFlags() can also take arrays like xajax->setFlags(array('debug'=>true,'outputEntities'=>true));

xajax->registerExternalFunction() has been integrated with xajax->registerFunction() so that there is now an optional second parameter in xajax->registerFunction() eg xajax->registerFunction('functionName', 'file.php')


xajaxResponse Methods

Most xajaxResponse methods have changed. The confusing 'add' prefix has been removed from most of the functions; so, xajaxResponse->addScript() becomes xajaxResponse->script(), xajaxResponse->addAssign() becomes xajaxResponse->assign(). This makes it fun to chain responses together with PHP5:

$response
 ->alert("Hi!")
 ->assign("myDiv""innerHTML"$stuff)
 ->plugin('script.aculo.us')->highlight("myDiv")
 ->scriptCall('finishEditing'$newID);

xajaxResponse->getXML() is gone; just return the xajaxResponse object.

[edit] Update to the latest xajax 0.5

Currently, xajax 0.5 beta 3 is the latest version. At this point you should not notice a large number of syntax changes. There are, however, a number of functions that have been marked as deprecated. As soon as possible, you should update your scripts to use the new versions of these functions as they will be removed from xajax in a future update.

[edit] Update your include directives

The xajax folder structure has changed to allow seperation of PHP and Javascript files. All PHP files are in xajax_core and all Javascript files are in xajax_js.

[edit] Update deprecated functions to their new versions

Most noteworthy are the following changes:

$xajax->debugOn();                   is now     $xajax->configure('debug', true);
$xajax->setRequestURI(...);          is now     $xajax->configure('requestURI', ...);
$xajax->registerFunction(...);       is now     $xajax->register(XAJAX_FUNCTION, ...);
$xajax->registerCallableObject(...); is now     $xajax->register(XAJAX_CALLABLE_OBJECT, ...);

If you use a 'loading...' message on your page, you will need to update your javascript code. xajax 0.5 is quite flexible in this regard, so here are the three methods you can use to declare a loading message in javascript:

Configure it globally so all requests use it:

xajax.callback.global.onRequestDelay = showLoadingMessage;

Configure it locally, so only certain requests use it:

myCallback = xajax.callback.create(100, 10000);
myCallback.onRequestDelay = showLoadingMessage;
// then, on the PHP side, specify the callback option when registering your function:
$xajax->register(XAJAX_FUNCTION, 'myFunction', array(
    'callback' => 'myCallback'
    ));

Configure it for a single request:

$xajax->register(XAJAX_FUNCTION, 'myFunction', array(
    'onRequestDelay' => 'showLoadingMessage'
    ));


Bold text==Quick Reference==

Old CodeNew Code
 
require_once('xajax.inc.php');require('xajax_core/xajax.inc.php');
 
xajax->debugOn();xajax->configure('debug',true);
xajax->debugOff();xajax->configure('debug',false);
xajax->statusMessagesOn();xajax->configure('statusMessages',true);
xajax->statusMessagesOff();xajax->configure('statusMessages',false);
xajax->decodeUTF8InputOn();xajax->configure('decodeUTF8Input',true)
xajax->registerExternalFunction('function','file.php');xajax->register(XAJAX_FUNCTION, new xajaxUserFunction('function', 'file.php'));
xajax->processRequests();xajax->processRequest();
 
xajaxResponse->loadXML($response);xajaxResponse->loadCommands($response);
return xajaxResponse->getXML();return xajaxResponse;
 
xajaxResponse->addAlert();xajax->alert();
xajaxResponse->addAppend();xajax->append();
xajaxResponse->addAssign();xajax->assign();
 
xajaxResponse->addClear();xajax->clear();
xajaxResponse->addCreateInput();xajax->createInput();
xajaxResponse->addCreate();xajax->create();
 
xajaxResponse->addInsertAfter();xajax->insertAfter();
 
xajaxResponse->addRedirect();xajax->redirect();
xajaxResponse->addRemove();xajax->remove();
 
xajaxResponse->addScript();xajax->script();
xajaxResponse->addScriptCall();xajax->call();
 
xajax.createInput() xajax.forms.createInput()
xajax.create() xajax.dom.create()
xajax.remove() xajax.dom.remove()
xajax.loadingFunction = function(){}; xajax.callback.global.onRequest= function(){};
xajax.doneLoadingFunction = function(){}; xajax.callback.global.onComplete= function(){};
new functionxajax.callback.global.onFailure = function(args)

{
alert("In global.onFailure...HTTP status code: " + args.request.status);
}