Welcome Guest, Not a member yet? Register   Sign In
using my library method in XML-RPC
#1

[eluser]kylehase[/eluser]
Getting the following error when trying to use a method in my library from XML-RPC.

PHP Fatal error: Call to undefined function: test() in /system/libraries/Xmlrpcs.php on line 324

XMLRPC server code
Code:
<?php
class Xmlrpc extends Controller {

  function index()
  {
    $this->load->library('accountmgr');
    $config['functions']['test'] = array('function' => 'accountmgr.test');
    $this->xmlrpcs->initialize($config);
    $this->xmlrpcs->serve();
  }
}

Accountmgr code (Accountmgr.php in system/application/libraries)
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Accountmgr {

  function test($request)
  {
    $CI =& get_instance();
    $parameters = $request->output_parameters();
    $response = array(array('you_said'  => $parameters[0]), 'struct');
    return $CI->xmlrpc->send_response($response);
  }
}

?>
#2

[eluser]kylehase[/eluser]
Fixed syntax in post above but that wasn't the problem.
#3

[eluser]Seppo[/eluser]
That's funny... lines 325-327 are commented... I tried uncommenting them and commenting lines 323-324 and it works...
I'm not sure if it's a bug or an intended behaviour, or the method must be defined inside the controller and the docs wasn't updated...
#4

[eluser]kylehase[/eluser]
I saw those commented lines as well and thought that I had done that (though I rarely ever change core code) so I re-downloaded 1.6.1 to verify that those // are in the original code. Assuming that the core code was right and I was wrong, I didn't try uncommenting it.
#5

[eluser]Derek Jones[/eluser]
Added an 'object' key to the XML-RPCS config that should take care of the problem. If you care to test it, it is available in the svn.
#6

[eluser]Elliot Haughin[/eluser]
I think there is still an issue loading methods from another controller.
I get 'not valid method' error using this code:

Code:
<?php
    
    class Api extends Controller {
    
        function Api()
        {
            parent::Controller();
            
            log_message('debug', 'Api received method');
        }
        
        function index()
        {
            $this->load->library('xmlrpc');
            $this->load->library('xmlrpcs');
            $this->load->library('server');

            $config['functions']['Posts.getLatest']     = array('function' => 'Posts.getLatest');
            $config['functions']['Posts.getSingle']     = array('function' => 'Posts.getSingle');
            
            $config['object'] = $this;
            
            $this->xmlrpcs->initialize($config);
            
            $this->xmlrpcs->serve();
        }
    }
    
?>

and controllers/posts.php:

Code:
<?php
    
    class Posts extends Controller {

        function Posts()
        {
            parent::Controller();
            
            $this->load->library('xmlrpc');
            $this->load->library('xmlrpcs');
            $this->load->library('server');
        }
        
        function getLatest($request)
        {
            $params = $this->server->prep_request($request);
            
            if    (!empty($params[0]))
            {
                $limit = $params[0];
            }
            else
            {
                $limit = 'none';
            }
            
            $response = array('you want posts! limit '.$limit, 'string');
            
            return $this->server->send_response($response);
        }
    }

?>
#7

[eluser]Derek Jones[/eluser]
I replied to the bug tracker as well, but for sake of continuity:

The object that you feed to $config[’object’] needs to be an instantiated class object that is callable via $OBJ->method_name(), so if you are feeding it $this, it would have to be a method within that class, in this case, the Api class. Make sense?
#8

[eluser]Derek Jones[/eluser]
Just checking up to see if you've gotten this working, Elliot?
#9

[eluser]kylehase[/eluser]
I've upgraded my project to 1.6.2 but it looks like this fix did not make that release. I haven't tried the SVN release yet.
#10

[eluser]Derek Jones[/eluser]
The aforementioned fix is indeed in 1.6.2.

http://dev.ellislab.com/svn/CodeIgniter/...mlrpcs.php




Theme © iAndrew 2016 - Forum software by © MyBB