Hi,
i copied the below code from the forum in openERP to Malaysia OpenERP - instant-erp web site , i do this reason is to prevent some good pointer to start something new may loss after changes / upgrade of forum application,
i have lots of good bookmarks of topic in the openobject forum , but after update , i lost all of them and
i think from now on , if i find any good topic ,i will re-post it over here!
ok , let is the forum post
Note that it's not necessary in PHP to specify the type of all arguments given to XML-RPC calls if you use php_xmlrpc_encode() function. In fact, we had something similar to what you did which avoids passing $uid and parameter types in each call:
We didn't need create, write, unlink or action, but is the code that implements login, search and read, in case it's useful to anyone:
{
public $user;
public $userId;
public $password;
public $database;
public $url;
public $connection;
function __construct($user, $password, $database, $url)
{
$this->user = $user;
$this->password = $password;
$this->database = $database;
$this->url = $url;
}
function login()
{
$msg = new xmlrpcmsg('login');
$msg->addParam(new xmlrpcval($this->database, "string"));
$msg->addParam(new xmlrpcval($this->user, "string"));
$msg->addParam(new xmlrpcval($this->password, "string"));
$connection = new xmlrpc_client($this->url.'common');
$resp = $connection->send($msg);
$val = $resp->value();
$this->userId = $val->scalarVal();
return $this->userId;
}
function search($relation,$domain)
{
$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($this->database, "string"));
$msg->addParam(new xmlrpcval($this->userId, "int"));
$msg->addParam(new xmlrpcval($this->password, "string"));
$msg->addParam(new xmlrpcval($relation, "string"));
$msg->addParam(new xmlrpcval("search", "string"));
$msg->addParam(php_xmlrpc_encode($domain));
$connection = new xmlrpc_client($this->url.'object');
$resp = $connection->send($msg);
//echo "FAULT: " . $resp->faultString();
$val = $resp->value();
return php_xmlrpc_decode($val);
}
function read($relation,$ids,$fields=array(),$context=array())
{
$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($this->database, "string"));
$msg->addParam(new xmlrpcval($this->userId, "int"));
$msg->addParam(new xmlrpcval($this->password, "string"));
$msg->addParam(new xmlrpcval($relation, "string"));
$msg->addParam(new xmlrpcval("read", "string"));
$msg->addParam(php_xmlrpc_encode($ids));
$msg->addParam(php_xmlrpc_encode($fields));
$connection = new xmlrpc_client($this->url.'object');
$resp = $connection->send($msg);
$val = $resp->value();
return php_xmlrpc_decode($val);
}
}
i copied the below code from the forum in openERP to Malaysia OpenERP - instant-erp web site , i do this reason is to prevent some good pointer to start something new may loss after changes / upgrade of forum application,
i have lots of good bookmarks of topic in the openobject forum , but after update , i lost all of them and
i think from now on , if i find any good topic ,i will re-post it over here!
ok , let is the forum post
Note that it's not necessary in PHP to specify the type of all arguments given to XML-RPC calls if you use php_xmlrpc_encode() function. In fact, we had something similar to what you did which avoids passing $uid and parameter types in each call:
Code:
$server = new OpenErpConnection($user, $password, $database, $url);
$server->login();
$domain = array(array('ref','=',$code),array('password','=',$_POST['password']));
$ids = $server->search('res.partner', $domain);
$server->read('res.partner', $ids, array('id','name','code') );
$server->login();
$domain = array(array('ref','=',$code),array('password','=',$_POST['password']));
$ids = $server->search('res.partner', $domain);
$server->read('res.partner', $ids, array('id','name','code') );
We didn't need create, write, unlink or action, but is the code that implements login, search and read, in case it's useful to anyone:
Code:
class OpenErpConnection{
public $user;
public $userId;
public $password;
public $database;
public $url;
public $connection;
function __construct($user, $password, $database, $url)
{
$this->user = $user;
$this->password = $password;
$this->database = $database;
$this->url = $url;
}
function login()
{
$msg = new xmlrpcmsg('login');
$msg->addParam(new xmlrpcval($this->database, "string"));
$msg->addParam(new xmlrpcval($this->user, "string"));
$msg->addParam(new xmlrpcval($this->password, "string"));
$connection = new xmlrpc_client($this->url.'common');
$resp = $connection->send($msg);
$val = $resp->value();
$this->userId = $val->scalarVal();
return $this->userId;
}
function search($relation,$domain)
{
$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($this->database, "string"));
$msg->addParam(new xmlrpcval($this->userId, "int"));
$msg->addParam(new xmlrpcval($this->password, "string"));
$msg->addParam(new xmlrpcval($relation, "string"));
$msg->addParam(new xmlrpcval("search", "string"));
$msg->addParam(php_xmlrpc_encode($domain));
$connection = new xmlrpc_client($this->url.'object');
$resp = $connection->send($msg);
//echo "FAULT: " . $resp->faultString();
$val = $resp->value();
return php_xmlrpc_decode($val);
}
function read($relation,$ids,$fields=array(),$context=array())
{
$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval($this->database, "string"));
$msg->addParam(new xmlrpcval($this->userId, "int"));
$msg->addParam(new xmlrpcval($this->password, "string"));
$msg->addParam(new xmlrpcval($relation, "string"));
$msg->addParam(new xmlrpcval("read", "string"));
$msg->addParam(php_xmlrpc_encode($ids));
$msg->addParam(php_xmlrpc_encode($fields));
$connection = new xmlrpc_client($this->url.'object');
$resp = $connection->send($msg);
$val = $resp->value();
return php_xmlrpc_decode($val);
}
}
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :