2013-01-10 40 views
1

嗨,我是Open ERP的新成員,我想用Open方法更新Open ERP中的記錄。用於更新的下面的代碼是從上一個doc.openerp.comexample什麼是xml-rpc處理程序?

/** 
* $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; 
} 

在當我調用寫入功能,然後我要通過爲$客戶端的第一個參數上面的代碼是XML-RPC處理程序。但我不清楚什麼是xml-rpc處理程序。請幫幫我。

+0

,如果這是你的* *代碼,相信你會知道什麼是類'$ client'是..? – dualed

+0

這不是我的代碼,它是在Open ERP站點上發佈的示例代碼(http://doc.openerp.com/v6.1/developer/12_api.html)。這就是爲什麼我不清楚這一點。 @Kumar – Kumar

+0

你應該在你的問題中更清楚一些:「以下是*我的代碼*更新」 – dualed

回答

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

?>