1

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

/**
* $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 处理程序。请帮我。

4

1 回答 1

2

嗨,最后我得到了解决方案,代码如下:

<?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';

?> 
于 2013-01-11T05:20:38.623 回答