Quick links: Content - sections - sub sections
EN FR

Table of content

Jelix supports xml-rpc. this a protocol specified for data exchange in XML format.A client send a request containing XML content, an action to execute and parameters. Server executes action indicated with its parameters and send back an XML result.

RPC = remote procedure call

Entry point

An XML-RPC request cannot be treated as a classic request, thus you can't use "classic" request object. You have to create a specific entry point in www/ directory, xmlrpc.php. This entry point will instantiate a jXmlRpcRequest instead of a jClassicRequest.

The new entry point should look like:


require_once ('../../lib/jelix/init.php');
require_once ('../../MYAPPLI/application.init.php');

$config_file = 'xmlrpc/config.ini.php';

require_once (JELIX_LIB_CORE_PATH.'request/jXmlRpcRequest.class.php');

$jelix = new jCoordinator($config_file);
$jelix->process(new jXmlRpcRequest());

Don't forget to add this entry point in urls engine configuration section. If you have selected simple url engine, in section simple_urlengine_entrypoints configuration file, just add:


xmlrpc = "@xmlrpc"

xmlrpc is the entry point name and @xmlrpc is the entry point request type.

If you have selected significant url engine, just add :


<jsonrpcentrypoint name="xmlrpc " default="true" />

Independently of url engines, you retrieve an url for a jsonrpc action like this:


  $url = jUrl::get("module~action@xmlrpc ");

Controller

As XML-RPC is a specific request type, a controller filename must be suffixed by ".xmlrpc.php". A "default" controller file would be: "default.xmlrpc.php". (it can co-exists with a "default" classic controller such as "default.classic.php").

Controller content is similar to those of a classic controller. You just have to use a jResponseXmlRpc response (alias:"xmlrpc"):


class defaultCtrl extends jController {

  function index(){

    $resp = $this->getResponse('xmlrpc');

    // any data types : integer, string, array, objects...
    $data_php = ... ;

    $resp->response = $data_php;

    return $resp;

  }
}

Client request

To send a XML-RPC request, as specified in xml-rpc spec, you have to use a specific XML string:


<?xml version="1.0" ?>
<methodCall>
   <methodName>module:default:index</methodName>
  <params>
     <param><string>Allo ?</string></param>
  </params>
</methodCall>

methodName parameter indicates which action to execute. In a Jelix application, it must be an action selector:


method:"myModule:default:index"

Note: "~" can not be used as separator between module name and action name. It must be replaced by ":" (tilde character is not permitted in XML-RPC method name). As a result, it is mandatory to indicate in the selector: a module, a controller and an action.


  $parameters = $this->param('params');

Of course, $parameters will contain "php" datas. the XML string is decoded by jXmlRpcRequest..

An HTMl example: TODO.