dqqlziv195281 2012-01-31 07:02
浏览 76

将OpenERP与CodeIgniter XML RPC库连接

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

  • 写回答

2条回答 默认 最新

  • duanrong5927 2012-01-31 19:42
    关注

    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?

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看