USING PHPLIVEX 2.2

ConstructorDescription
PHPLiveX($functions) Starts to handle ajax requests. Exports php functions for ajax.
$functions parameter: Optional. Its value is function names (if more than 1, seperated by commas);

MethodDescription
Export("functionNames,...") Exports the functions for ajax. Can only be called over run method.
Parameter Value: Function names
(if more than 1, seperated by commas);
ExportClassFunctions("objectName->methodName,...") Exports class functions for ajax. Can only be called over run method.
Parameter Value: objectName (like myObject in "$myObject = new myClass();"). methodName is name of the class function.
(if more than 1, seperated by commas);
ExportClass("objectNames,...") Exports all functions of the classes for ajax. Can only be called over run method.
Parameter Value: Class names
(if more than 1, seperated by commas);
Run()Creates javascript codes to handle ajax requests. Must be called between script tags

At first, you must create the phplivex object. To export your functions, you can use both constructor function and export method.
<?
function myFunction($text){
   return $txt;
}

$plx = new PHPLiveX("myFunction");

OR

$plx = new PHPLiveX();
$plx->Export("myFunction");
?>

If you want to export a class function, you must create the instance at first. Then you can export its functions as in the example. Note that this property uses session so it needs session_start() ahead.

<?
class myClass(){
    var $Text;

    function myClass($text){
        $this->Text = $text;
    }

    function setText(){
        return $this->Text;
    }
}

$test = myClass("it's very easy-to-use");

$plx->ExportClassFunctions("test->setText");
//OR
$plx->ExportClass("test"); // may be used.
?>


You must call run method between script tags anywhere on the page. But give attention that methods under run method does not work. So it's better to call it at the end of the page.
<script language="javascript">
<? $plx->Run(); ?>
</script>

You can call your exported functions via javascript. The global functions are called directly with its name (e.g. myFunction) but the class functions are called with #ưnstanceName__functionName# (e.g. test__setText).
In order to call these functions, you must enter necessary parameters below within one last argument. But all of these properties are optional. If you don't use any of them(leave the argument empty), the function runs without returning a value.
ParameterDescription
typeCan take only one value "r". If you want to get returned value of the function (e.g. give the value to a variable). And if this parameter is used, the others cannot be used. Note that if this parameter is used, the ajax request runs synchronously. (During the process, no other function runs.)
target Takes the ID value of a DOM element and returned value of the function is printed to its innerHTML. If this parameter is used as "target=alert", the returned value is alerted.
modeIts default value is "rw"(rewrite) which means rewriting the value to the target. If you use "aw" (append), the value is appended to the initial innerHTML of target.
preloadCan take the ID value of a DOM element used for preload. It must be hidden(style="visibility:hidden") initially. During the process, the foregoing element is made visible and then hidden when the process finishes. Note that this parameter can not be used with type together.
method Can take "post" and "get" values. These are the http-methods of the xmlhttp request. Default value is get. Added in version 2.1.

<?
<a href="javascript:myFunction('it is an example', 'target=showText,preload=loadSpan');">test it</a>

<span id="showText"></span>
<span id="loadSpan" style="visibility:hidden">Loading...</span>
?>
The function ahead prints "it is an example" to the innerHTML of the DOM element(span) whose id is "showText". It also uses preloading by displaying "Loading..." text during the process. The mode parameter is "rw" by default. By each click on the anchor, foregoing span shows the same text. But if "mode=aw" parameter is added, the text will append to the initial value. For example; after 3 calls, innerHTML of the span becomes "it is an exampleit is an exampleit is an example". If you don't use preload parameter, there won't be any preloading. In addition, you don't have to use target method. For example; supposing that your function just updates database, you don't define a target and it doesn't print anything.

<?
<script language="javascript" >
var output = test__setText("an example", "type=r");
# ...
</script>
?>
As this function use "type=r" parameter, the value it returns is given to a variable.