Help with XML_RPC Library : How to return message from nested method

#1
[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'));
    
    }
    
}

#2
[eluser]drewbee[/eluser]
I guess I am a little confused as to what you are wanting? Is this what you mean?

Code:
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' => $load);
            return $this->xmlrpc->send_response(array($data, 'struct'));
    
    
    }
    
}

#3
[eluser]louis w[/eluser]
I need to call xmlrpc->send_response directly from the doWhatever() method. Is there anyway this is possible?

#4
[eluser]drewbee[/eluser]
Code:
public function loadPage($request) {
    
            $this->load->library('xmlrpc');
            
            $params = $request->output_parameters();
            $params = $params[0];
            // will return xmlrpc->send_response() returned value
            return $this->_doWhatever();

    
    }
    
}

#5
[eluser]louis w[/eluser]
Sorry that won't work.

Let me explain what is going on here, I didn't want to give too many details to over complicate things.

loadPage gets called to load a page, this method then needs to call a second method and store it's value in a variable ($load = $this->doWhatever()Wink. $load needs to rename a variable. I need to be able to stop this process from anywhere along the line and return an error without having to return it all the way down the chain.

Currently in a non XML-RPC site this can be done easily with show_error which just sends the data to output library and calls exit();.

Is there anyway type of thing can be done with the XML-RPC library?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.