Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

php - How to use PHP7 Ripcord library to get Odoo data?

I am trying to get some data from Odoo through XMLRPC, and I am working with PHP and its Ripcord library (recommended on https://www.odoo.com/documentation/8.0/api_integration.html).

So I am following the steps written on that page.

Firstly, I downloaded the Ripcord files from https://github.com/poef/ripcord.git. I saved them in a folder named ripcord, located at the index directory of my PHP page.

Secondly, I enabled the OpenSSL and XMLRPC extensions for PHP7. I think I did it well because if I execute the next sentence:

$modules = get_loaded_extensions();
foreach ($modules as $module) {
    echo $module.', ';
}

I get this result:

Core, date, libxml, openssl, pcre, zlib, filter, hash, Reflection, SPL, session, standard, apache2handler, mysqlnd, PDO, xml, calendar, ctype, curl, dom, mbstring, fileinfo, ftp, gd, gettext, iconv, json, exif, mcrypt, mysqli, pdo_mysql, Phar, posix, readline, shmop, SimpleXML, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xmlreader, xmlrpc, xmlwriter, xsl, Zend OPcache,

Now, this is the code of my index.php:

$url = 'http://localhost:30080';
$db = 'db_v80_test_01';
$username = 'admin';
$password = 'adminpwd';

require_once('ripcord/ripcord.php');

// $info = ripcord::client($url)->start(); 
// list($url, $db, $username, $password) = array($info['host'], $info['database'], $info['user'], $info['password']);

$common = ripcord::client($url.'/xmlrpc/2/common');

$uid = $common->authenticate($db, $username, $password, array());
die($uid);

The problem is that I am getting nothing in $uid variable. Can anyone tell me what is happening?

NOTE

May be this question is duplicated: Odoo API web service doesn't return anything

But as it had no answers, I tried to give more information on mine.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ok, I had not error log enabled in php.ini, so I always get nothing. If I had enabled it earlier, I would have seen that the error was that I was trying to print a kind of value I cannot print, so the problem was in the die command.

Now, it is working perfectly with this code:

$url = 'http://localhost:30080';
$db = 'db_v80_test_01';
$username = 'admin';
$password = 'adminpwd';

require_once('ripcord/ripcord.php');

$common = ripcord::client($url.'/xmlrpc/2/common');
$uid = $common->authenticate($db, $username, $password, array());
$models = ripcord::client("$url/xmlrpc/2/object");
$partners = $models->execute_kw(
    $db,
    $uid,
    $password,
    'res.partner',
    'search',
    array(
        array(
            array('is_company', '=', true),
            array('customer', '=', true)
        )
    )
);

echo('RESULT:<br/>');
foreach ($partners as $partner) {
    echo $partner.'<br/>';
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...