繁体   English   中英

Odoo 14 Webservices 通过外部 API (XMLRPC) 使用 PHP / Laravel

[英]Odoo 14 Webservices through External API (XMLRPC) using PHP / Laravel

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

I have tried python examples on above page which works fine... even from another machine's same vm (both vm's are Ubuntu 18.04 Desktop, running Odoo 14) I have not any idea of using/writing code in PHP , on my Windows host machine , I have downloaded XAMPP portable , enable xmlrpc in php.ini, installed ripcord library through composer , (as it uses in PHP examples in above official guide) started XAMPP controller + Apache, created a.php file in d:\xampp\htdocs \mytest\test.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还有什么我错过或必须配置的吗/settings 或者我也必须有 xmlrpc.php? 如果是,应该复制到哪里? 请帮忙,因为我自上周日以来一直在搜索和尝试,但仍然失败。 如果需要任何相关信息,请要求有足够的信息来解决问题。

工作正常的最终代码,从 res_partner 检索数据(“名称”)。 只是通知一下,我在 ubuntu 18.04 桌面上安装了 Odoo 14,将其网络设置为桥接并使用 Odo 的默认端口。 have XAMPP portable on my Win'7 host machine, created a project folder in D:\xampp\htdocs\mytest and cloned "ripcord" library with GitBash: git clone https://github.com/poef/ripcord

created.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>");
?>

快乐编码:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM