【问题标题】:What is xml-rpc handler?什么是 xml-rpc 处理程序?
【发布时间】:2013-01-10 10:04:20
【问题描述】:

您好,我是 Open ERP 的新手,我想使用写入方法更新 Open ERP 中的记录。以下更新代码来自doc.openerp.com上的example

/**
* $client = xml-rpc handler
* $relation = name of the relation ex: res.partner
* $attribute = name of the attribute ex:code
* $operator = search term operator ex: ilike, =, !=
* $id = id of the record to be updated
* $data = data to be updated
*/
include("xmlrpc.inc");
function write($client,$relation,$attribute,$operator,$data,$id) {
  var $user = 'admin';
  var $password = 'admin';
  var $userId = -1;
  var $dbname = 'db_name';
  var $server_url = 'http://localhost:8069/xmlrpc/';

  $id_val = array();
  $id_val[0] = new xmlrpcval($id, "int");

  if($userId<=0) {
     connect();
  }

  $msg = new xmlrpcmsg('execute');
  $msg->addParam(new xmlrpcval($dbname, "string"));
  $msg->addParam(new xmlrpcval($userId, "int"));
  $msg->addParam(new xmlrpcval($password, "string"));
  $msg->addParam(new xmlrpcval($relation, "string"));
  $msg->addParam(new xmlrpcval("write", "string"));
  $msg->addParam(new xmlrpcval($id, "array"));
  $msg->addParam(new xmlrpcval($data, "struct"));

  $resp = $client->send($msg);
  $val = $resp->value();
  $record = $val->scalarval();

  return $record;
}

在上面的代码中,当我调用 write 函数时,我必须传递 $client 的第一个参数是 xml-rpc 处理程序。但我不清楚什么是 xml-rpc 处理程序。请帮帮我。

【问题讨论】:

  • 如果这是你的代码,你肯定知道$client是什么类..?
  • 这不是我的代码,它是发布在 Open ERP 网站 (doc.openerp.com/v6.1/developer/12_api.html) 上的示例代码。这就是为什么我不清楚这一点。 @库马尔
  • 您的问题应该更清楚:“以下是 my Code 用于更新”
  • 那么可能是$sock = new xmlrpc_client($server_url.'common'); $client = $sock;。该页面上的示例有点烦人。
  • 我已经尝试过了,但它不起作用。

标签: php xml-rpc openerp


【解决方案1】:

嗨,我终于得到了解决方案,代码如下:

<?php
include("lib/xmlrpc.inc");

$arrayVal = array(
'name'=>new xmlrpcval('abc', "string") ,
'city'=>new xmlrpcval('xyz' , "string"),
'phone'=>new xmlrpcval('7894500000' , "string")
);

$client = new xmlrpc_client("http://17.23.28.60:8069/xmlrpc/object");
$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval("test", "string"));//database name
$msg->addParam(new xmlrpcval("1", "int"));//user id
$msg->addParam(new xmlrpcval("pwd", "string"));//password
$msg->addParam(new xmlrpcval("res.company", "string"));//module name
$msg->addParam(new xmlrpcval("write", "string"));//method name
$msg->addParam(new xmlrpcval("1", "int"));//record id that u want to update
$msg->addParam(new xmlrpcval($arrayVal, "struct"));//fileds to update
$resp = $client->send($msg);
if ($resp->faultCode())

echo 'Error: '.$resp->faultString();

else

echo 'Updated Successfully';

?> 

【讨论】:

    猜你喜欢
    • 2010-09-08
    • 1970-01-01
    • 2010-11-25
    • 2013-06-02
    • 2011-10-07
    • 2016-05-08
    • 2013-02-01
    • 2018-08-09
    • 1970-01-01
    相关资源
    最近更新 更多