[eluser]louis w[/eluser]
I am trying to figure out if it is possible to be able to send the response back from a another method called from the originator.
If you refer to the example below, the RPC Server calls loadPage, which would do some stuff including to call another method (or perhaps a model) to fetch data. I want the other method called to be able to send output (and stop the XMLRPC request from continuing, like show_error would).
Trying to do this without having _doWhatever() actually return it, because then I couldn't use the returned value as my data.
If you run the demo below it will return Array([data] => It worked.), when I want it to return the 'Something bad happened' string.
Could it be done by setting the data in the output library and somehow telling the application to stop processing?
Hope this makes sense.
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Site extends Controller {
function __construct() {
parent::__construct();
}
// ------------------------------------------------------------------------
function index() {
$this->load->library('xmlrpc');
$this->load->library('xmlrpcs');
$config['functions']['loadPage'] = array('function' => __CLASS__.'.loadPage');
$this->xmlrpcs->initialize($config);
$this->xmlrpcs->serve();
}
public function loadPage($request) {
$this->load->library('xmlrpc');
$params = $request->output_parameters();
$params = $params[0];
$load = $this->_doWhatever();
// Normally $load would now be the value of what we loaded, and we would do something
// with it here. But since this is a demo, just output something.
$data = array(
'data' => 'It worked.'
);
return $this->xmlrpc->send_response(array($data, 'struct'));
}
private function _doWhatever() {
// Do some checking here
// Whoops there is some kind of error
// This would normally be done with show_error();
$data = array(
'data' => 'Something bad happened.'
);
return $this->xmlrpc->send_response(array($data, 'struct'));
}
}