Mithun Sreedharan
Mithun Sreedharan

Reputation: 51292

Connecting OpenERP with CodeIgniter XML RPC library

I've the following Codeigniter XML RPC code for searching customers in a OpenERP database,

I' following this documentation for implementing search
The below code works fine and retrieves the all the records in res.partner table

    $this->xmlrpc->server('http://localhost/xmlrpc/object',8314);
    $this->xmlrpc->method('execute');   
    //$this->xmlrpc->set_debug(TRUE);       

   $request = array (
           array($this->database, 'string'),
           array($this->userid , 'int'),
           array($this->password, 'string'),  
           array("res.partner", 'string'), 
           array('search', 'string'),
           array(array(), 'array'),
         ); 
   $this->xmlrpc->request($request);
   if ( ! $this->xmlrpc->send_request())
    {
        echo $this->xmlrpc->display_error();
        return -1;
    }
    else 
    {
        //print_r( $this->xmlrpc->display_response());
        $val = $this->xmlrpc->display_response();
        return $val;
    }

Now I want to get only the items with name=abc

    $this->xmlrpc->server('http://localhost/xmlrpc/object',8314);
    $this->xmlrpc->method('execute');   
    //$this->xmlrpc->set_debug(TRUE);       
    $attribute = "name";
    $operator = "=";
    $keys="abc";

    $key = array(
        new XML_RPC_Values(array(
            new XML_RPC_Values($attribute , "string"),
            new XML_RPC_Values($operator,"string"),
            new XML_RPC_Values($keys,"string"))
        ,"array"),
    );
   $request = array (
           array($this->database, 'string'),
           array($this->userid , 'int'),
           array($this->password, 'string'),  
           array("res.partner", 'string'), 
           array('search', 'string'),
           $key,
         ); 
   $this->xmlrpc->request($request);
   if ( ! $this->xmlrpc->send_request())
    {
        echo $this->xmlrpc->display_error();
        return -1;
    }
    else 
    {
        //print_r( $this->xmlrpc->display_response());
        $val = $this->xmlrpc->display_response();
        return $val;
    }

This is not working and it thowss the following errors

A PHP Error was encountered
Severity: Notice
Message: Object of class XML_RPC_Values could not be converted to int
Filename: libraries/Xmlrpc.php
Line Number: 1216


A PHP Error was encountered
Severity: 4096
Message: Object of class XML_RPC_Values could not be converted to string
Filename: libraries/Xmlrpc.php
Line Number: 1360

the result is same all the records of the res.partner table is retrieved

Upvotes: 0

Views: 1939

Answers (2)

TimoSolo
TimoSolo

Reputation: 7325

Not sure if this is the problem I noticed that your "key" doesn't have a $. should be:

$request = array (
       array($this->database, 'string'),
       array($this->userid , 'int'),
       array($this->password, 'string'),  
       array("res.partner", 'string'), 
       array('search', 'string'),
       $key,
     ); 

Upvotes: 1

Don Kirkby
Don Kirkby

Reputation: 56230

It looks like your error is on the PHP side before you send the request, not in the OpenERP server.

I'm not sure, but the nesting level of the "array" type string in your second code snippet looks wrong.

Here's a trimmed version of your first, working snippet:

       ...
       $request = array (
           ...
           array('search', 'string'),
           array(array(), 'array'),
       ); 

Now here's a version of your second, broken snippet where I inlined the $key variable and trimmed some other stuff:

       $request = array (
           ...
           array('search', 'string'),
           array(
               new XML_RPC_Values(
                   array(
                       new XML_RPC_Values($attribute , "string"),
                       new XML_RPC_Values($operator,"string"),
                       new XML_RPC_Values($keys,"string")
                   ),
                   "array"
               ),
           ),
       ); 

You're passing an XML_RPC_Values object as the only parameter to an array. Does PHP expect an integer length when you pass in one parameter? If it does, then this error message makes sense:

Object of class XML_RPC_Values could not be converted to int

Is that outer XML_RPC_Values object even necessary?

Upvotes: 1

Related Questions