【问题标题】:Odoo 14 Webservices through External API (XMLRPC) using PHP / Laravel使用 PHP / Laravel 通过外部 API (XMLRPC) 的 Odoo 14 Web 服务
【发布时间】:2021-04-07 06:00:30
【问题描述】:

我想使用使用 PHP 的 Odoo 网络服务作为 Odoo 文档(Odoo 外部 API)的示例,链接在这里:Odoo External API

我已经在上面的页面上尝试过 python 示例,效果很好......即使来自另一台机器的同一个虚拟机(两个虚拟机都是 Ubuntu 18.04 桌面,运行 Odoo 14)我不知道在 PHP 中使用/编写代码,在我的 Windows 主机上,我已经下载了 XAMPP 便携,在 php.ini 中启用 xmlrpc,通过 composer 安装 ripcord 库 , (正如它在上面官方指南中的 PHP 示例中使用的那样)启动 XAMPP 控制器 + Apache,在 d:\xampp\htdocs\mytest\test.php 中创建了一个 .php 文件,代码如下:

<?php

//url = my ubuntu vm ipv4 with odoo default port
$url = "http://192.168.18.71:8069"; 
$db = 'odb';
$username = 'odoouser@myhost.com';
$password = 'admin';

require_once('ripcord.php');
$common = Ripcord::client($url'/xmlrpc/2/common');
$ver = $common->version();
echo $ver;
$uid = $common->authenticate($db, $username, $password, array());
echo $uid;
?>

在 Chrome 中运行页面,它显示 警告:require_once(ripcord.php): failed to open stream: No such file or directory in D:\xampp\htdocs\mytest\test.php还有什么我错过或必须配置/设置或我也必须有 xmlrpc.php 的吗?如果是,应该复制到哪里?请帮忙,因为我自上周日以来一直在搜索和尝试,但仍然失败。如果需要任何相关信息,请要求有足够的信息来解决问题。

【问题讨论】:

  • 感谢@Ajay,在我的搜索过程中,我看到了它,但问题是我不知道在我的 xampp 便携式环境中将下载的 ripcord 相关文件放在哪里?在那个问题中也没有提到。我已经提到我不知道如何使用 PHP。
  • 将其保存在名为 ripcord 的文件夹中,该文件夹位于 PHP 页面的索引目录中。C:/xampp/htdocs
  • @Ajay 将下载的文件夹(Ripcord-master)复制到 D:\xampp\htdocs\mytest\ 并重新启动 xampp + Apache,它显示几乎相同的错误。
  • 警告:require_once(ripcord.php):打开流失败:D:\xampp\htdocs\mytest\test.php 中没有这样的文件或目录致命错误:require_once():需要打开失败'ripcord.php' (include_path='\xampp\php\PEAR') 在 D:\xampp\htdocs\mytest\tests.php

标签: python php odoo xml-rpc


【解决方案1】:

工作正常的最终代码,从 res_partner 检索数据(“名称”)。只是通知一下,我在 ubuntu 18.04 桌面上安装了 Odoo 14,将其网络设置为 Bridge 并使用 Odo 的默认端口。在我的 Win'7 主机上安装 XAMPP,在 D:\xampp\htdocs\mytest 中创建了一个项目文件夹,并使用 GitBash 克隆了“ripcord”库:git clone https://github.com/poef/ripcord

创建 .php 文件(如下)并在 Chrome 中对其进行测试,它按预期显示来自 res_partner... 的名称列数据。

<?php
// Login information
$url = 'http://192.168.18.71:8069';
$url_auth = $url . '/xmlrpc/2/common';
$url_exec = $url . '/xmlrpc/2/object';
$db = 'odb14';
$username = 'odoouser@myhost.com';
$password = 'admin';
// Ripcord can be cloned from https://github.com/poef/ripcord
require_once('ripcord\ripcord.php');
// Login
$common = ripcord::client($url_auth);
$uid = $common->authenticate($db, $username, $password, array());
print("<p>Your current user id is '${uid}'</p>");
$models = ripcord::client($url_exec);
$models                 // The (Ripcord) client
    ->execute_kw(       // Execute command
    'table.reference',  // Referenced model, e.g. 'res.partner' or 'account.invoice'
    'search',           // Search method of the referenced model
    array()             // Search domain
);
$customer_ids = $models->execute_kw(
    $db, // DB name
    $uid, // User id, user login name won't work here
    $password, // User password
    'res.partner', // Model name
    'search', // Function name
    array( // Search domain
        array( // Search domain conditions
            array('active', '=', true))
        )
 );
$customers = $models->execute_kw($db, $uid, $password, 'res.partner',
    'read',  // Function name
    array($customer_ids), // An array of record ids
    array('fields'=>array('name')) // Array of wanted fields
);
print("<p><strong>Found customers:</strong><br/>");
foreach ($customers as $customer){
    print("{$customer['name']}<br/>");
}
print("</p>");
?>

编码愉快 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-30
    相关资源
    最近更新 更多