[eluser]gtech[/eluser]
Hi i gave your code a go, and found a solution.. you were very close.
here is what I did, note the php_xmlrpc_encode was the problem as you thought.. the parameters I passed also gets passed in as an array, so I simply return $pars[0].
hope this helps.
Code:
<?php
include('lib/xmlrpc.inc');
include('lib/xmlrpcs.inc');
$c = new xmlrpc_client('/CI1.6.1/index.php/cif_s', 'localhost', 80); // Set up client
// I managed to use this way of passing the params.
$msg = new xmlrpcmsg('Add_contact', array(new xmlrpcval('param1','string'),new xmlrpcval(2,'int')));
$r = $c->send($msg);
echo '<pre>';
print_r( $r );
echo '</pre>';
?>
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Cif_s extends Controller {
function Cif_s() {
parent::Controller();
}
/*--------------------------------*/
function index() {
$this->load->library('xmlrpc');
$this->load->library('xmlrpcs');
$config['functions']['Add_contact'] = array('function' => 'Cif_s.add_contact');
$this->xmlrpcs->initialize($config);
$this->xmlrpcs->serve();
}
/*--------------------------------*/
function add_contact($request) {
$pars = $request->output_parameters();
// I return $pars[0] I could also return $pars[1]
$response = array(
array('pars' => array($pars[0], 'string')
),'struct');
return $this->xmlrpc->send_response($response);
}
}
?>
RESPONSE:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>pars</name>
<value>
<string>param1</string>
.....
//woo hoo it worked