Viewed   129 times

here is the part if having error.

Fatal error: Using $this when not in object context in /pb_events.php on line 6

line 6 is: $jpp = $this->vars->data["jpp"];

function DoEvents($this) {

    global $_CONF, $_PAGE, $_TSM , $base;

    $jpp = $this->vars->data["jpp"];

    $cache["departments"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_departments]}");
    $cache["locations"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_location]}");
    $cache["names"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_names]}");
    $cache["categories"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_categories]}");

Thanks a lot! appreciate!

 Answers

4

$this only makes sense in methods, not in functions

this is ok

class Foo {
     function bar() {
          $this->...

this is not

function some() {
    $this->

// edit: didn't notice he passes "$this" as parameter

advice: simply replace "$this" with "$somethingElse"

Monday, October 10, 2022
1

$this will not be available in a static function. You'll probably want to re-create $app within the static function:

static function store($key, $value)
{
    $app = base_url('application') . '/cache/';
    $key = sha1($key);
    $value = serialize($value);
    file_put_contents( $app . $key.'.cache', $value);
}

I'm not quite sure what you're trying to do in the grand context of your application, but you may not even need a static method in the first place.

Wednesday, August 10, 2022
3

So, after more testing and what not, I find that it's not actually a bug in the MySQLi libraries or in my code.

The Solution? Give the database user the "Execute" permission for the database in MySQL. I wrote and tested the SQL statements and functions while I was logged in as root, not the actual user that the script was using.

Oh the joys of IT.

Monday, September 19, 2022
3

1°) After a while searching for a solution, I finally decided to purchase some modules, instead of using the Odoo Demo account.

So, I just changed the credentials for my new database, and also opened the 8069 port for that specific URL. And it worked :)

Code :


$url = 'https://thedatabasename.odoo.com';  // Edited here. Opening the 8069 port was the last step to make it work :)
$db = 'thedatabasename';                // Edited here
$username = 'usernameofthataccount';    // Edited here
$password = 'passwordofthataccount';    // Edited here

require_once('ripcord/ripcord.php');

$common = ripcord::client($url.'/xmlrpc/2/common');
$uid = $common->authenticate($db, $username, $password, array());

echo('UID:');
var_dump($uid);
echo('<br/>');

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

echo('RESULT:<br/>');
foreach ($partners as $partner) {
    echo 'partner=['.$partner.']<br/>';
}
 
echo('VAR_DUMP:<br/>');
var_dump($partners);

Output :


UID:int(2)
RESULT:
partner=[568]
partner=[570]
partner=[293]
partner=[378]
partner=[526]
VAR_DUMP:
array(193) { [0]=> int(568) [1]=> int(570) [2]=> int(293) [3]=> int(378) [4]=> int(526)}

2°) The start( ) method won't work with the specific URL though

So, I'm not sure that the start( ) method will work with something else than a Demo account.

Also, Odoo's support told me to not include the "/start" part of the URL in the script. But, with or without the "/start" part, it didn't work.

Code :


require_once('ripcord/ripcord.php');
$info = ripcord::client('https://thedatabasename.odoo.com/start')->start(); // Even using the specific IP, this is ot working in my case

echo 'hello';

Output :


Fatal error: Uncaught Ripcord_TransportException: Could not access http://102.16.10.74:8069/start/ in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php:488 Stack trace: #0 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php(228): Ripcord_Transport_Stream->post('http://102.16.1...', '<?xml version="...') #1 /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/index.php(11): Ripcord_Client->__call('start', Array) #2 {main} thrown in /var/www/vhosts/mywebsiteexample.com/preprod.mywebsiteexample.com/ripcord/ripcord_client.php on line 488

My Conclusion is :

Odoo DEMO has NOT worked for me, even if I followed the instructions from here :

Odoo's documentation

EDIT :

1°) a/ We can get an IP Address (url is like "http://xxx.xxx.xxx.xxx") when we install manually our odoo server onto a different host server of our choice.

1°) b/ But if the odoo server is installed onto Odoo's official website (url is like "https://thedatabasename.odoo.com"), we have no IP Address. And I managed to open the 8069 port by asking for it to the web host support of my website.

So, to make it simple, I edited "http://xxx.xxx.xxx.xxx" to "https://thedatabasename.odoo.com", for the case 1°) b/ :

$url = 'https://thedatabasename.odoo.com';
$db = 'thedatabasename';
Friday, November 11, 2022
 
3

In my index.php I'm loading maybe foobarfunc() like this:

 foobar::foobarfunc();  // Wrong, it is not static method

but can also be

$foobar = new foobar;  // correct
$foobar->foobarfunc();

You can not invoke method this way because it is not static method.

foobar::foobarfunc();

You should instead use:

foobar->foobarfunc();

If however you have created a static method something like:

static $foo; // your top variable set as static

public static function foo() {
    return self::$foo;
}

then you can use this:

foobar::foobarfunc();
Thursday, November 10, 2022
 
khalos
 
1

Like the error says, you can't use $this outside of the class definition. To use $_db outside the class definition, first make it public instead of private:

public $_db

Then, use this code:

$authDb = new AuthDb();
$authDb->_db->prepare($query); // rest of code is the same

--

You have to understand what $this actually means. When used inside a class definition, $this is used to refer to an object of that class. So if you had a function foo inside AuthDB, and you needed to access $_db from within foo, you would use $this to tell PHP that you want the $_db from the same object that foo belongs to.

You might want to read this question: PHP: self vs $this

Sunday, October 9, 2022
 
novice
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :