Skip to Content
Menu
This question has been flagged
1 Reply
5879 Views

I am trying to follow example here: https://github.com/Tawasta/odoo-xml-rpc-example/blob/10.0/php-ripcord.md

Odoo is running under ubuntu 18.04 desktop linux and my host is win'7, here i have xampp portable.

i can get uid ( print("<p>Your current user id is '${uid}'</p>"); ) but when going further it is showing error

Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\mytest\test4.php on line 54


Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\mytest\test4.php on line 54

Warning: Illegal string offset 'name' in D:\xampp\htdocs\mytest\test4.php on line 54

the code file .php contains:

<?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)) // Query condition
        )
 );

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

is it because of my odoo version where it requires different handling or anything else? please help.

regards


Avatar
Discard
Author

now it is showing name field data but another error with every name: Warning: Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\mytest\test4.php on line 53

Author Best Answer

 final code which works fine, retrieve data ('name') from res_partner. just to inform, i have Odoo 14 installed on a ubuntu 18.04 desktop, sets its network as Bridge and used Odo's default port. 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 file (below) and test it in Chrome, it is showing name column data from res_partner... as expected.

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


Avatar
Discard
Related Posts Replies Views Activity
0
Mar 18
3122
1
Mar 15
6188
2
Mar 15
9150
1
Jan 23
3958
1
May 18
4689