您好我是Open ERP的新手,我想使用Write Method更新Open ERP中的记录。以下用于更新的代码来自example上的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处理程序。请帮帮我。
答案 0 :(得分: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';
?>