如何使用PHP7 Ripcord库获取Odoo数据? [英] How to use PHP7 Ripcord library to get Odoo data?

查看:173
本文介绍了如何使用PHP7 Ripcord库获取Odoo数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过XMLRPC从Odoo中获取一些数据,并且我正在使用PHP及其Ripcord库(推荐在

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.

首先,我从 https://github.com/poef/ripcord.git下载了Ripcord文件.我将它们保存在一个名为 ripcord 的文件夹中,该文件夹位于我的PHP页面的索引目录中.

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.

第二,我为PHP7启用了OpenSSL和XMLRPC扩展.我认为我做得很好,因为如果我执行下一个句子:

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.', ';
}

我得到这个结果:

核心,日期,libxml, openssl ,pcre,zlib,过滤器,哈希,反射, SPL,会话,标准,apache2handler,mysqlnd,PDO,xml,日历, ctype,curl,dom,mbstring,fileinfo,ftp,gd,gettext,iconv,json, exif,mcrypt,mysqli,pdo_mysql,Phar,posix,readline,shmop, SimpleXML,套接字,sysvmsg,sysvsem,sysvshm,令牌生成器,wddx, xmlreader, xmlrpc ,xmlwriter,xsl,Zend OPcache

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,

现在,这是我的index.php的代码:

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

问题是在$uid变量中我什么也没得到.谁能告诉我发生了什么事?

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

注意

可能是重复的问题: Odoo API网络服务未返回任何东西

但是由于没有答案,我试图提供有关我的更多信息.

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

推荐答案

好吧,我没有在php.ini中启用错误日志,因此我始终一无所获.如果我早些时候启用了它,我会发现错误是我试图打印一种我无法打印的值,所以问题出在die命令中.

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

这篇关于如何使用PHP7 Ripcord库获取Odoo数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆