PDA

View Full Version : Data Manager Programming Problems


calwebsnc
07-20-2010, 10:46 AM
Hi,
I'm trying to develop a class to write new threads on vbulletin.

This is my code

<?php

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');


class codeigniter_bridge{

function codeigniter_bridge(){

echo "Create Object <br/>";

$this->threaddm =& datamanager_init('Thread', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

echo "Object Created<br/>";
}


function postThread(){
echo "Call Prova<br/>";
$class_methods = get_class_methods($this->threaddm);

foreach ($class_methods as $method_name) {
echo "$method_name\n";
}

}
}

$vb = new codeigniter_bridge();
$vb->postThread();
?>


and this is what appens:
http://www.cyberludus.com/forum/codeigniter_bridge.php

Where I do wrong?

Thank you!

Guest190829
07-21-2010, 06:58 PM
You need to pass a valid vBulletin registry object to the datamanager; in your script, $vbulletin doesn't have the proper scope in your method.

Pass $vbulletin through the constructor:


function codeigniter bridge(&$registry) {
$this->registry =& $registry;
}

// *** .....

$vb =& new codeigniter_bridge($vbulletin);

James Birkett
07-21-2010, 07:11 PM
You need to pass a valid vBulletin registry object to the datamanager; in your script, $vbulletin doesn't have the proper scope in your method.

Pass $vbulletin through the constructor:


function codeigniter bridge(&$registry) {
$this->registry =& $registry;
}

// *** .....

$vb =& new codeigniter_bridge($vbulletin);



Wouldn't you consider it bad practice to pass the variables via referencing considering it's deprecated in 5.3?

Guest190829
07-21-2010, 07:21 PM
Wouldn't you consider it bad practice to pass the variables via referencing considering it's deprecated in 5.3?

Well I saw he had PHP 4 specific syntax (such as the constructor), so I provided my code with the same OO flavor. If you are running < PHP 5, you have to explicitly pass by reference or else you'll get some funky results.

calwebsnc
07-21-2010, 07:46 PM
Ok, now it works!
Thank you.

<?php

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');


class codeigniter_bridge{

function codeigniter_bridge(&$registry){

echo "Create Registry <br/>";

$this->Registry =& $registry;

echo "Is registry an object? ".is_object($this->Registry)."<br/>";

echo "Create Object <br/>";

$this->threaddm =& datamanager_init('Thread', $this->Registry, ERRTYPE_ARRAY, 'threadpost');

echo "Object Created<br/>";
}


function postThread(){
echo "Call Prova<br/>";
$class_methods = get_class_methods($this->threaddm);

foreach ($class_methods as $method_name) {
echo "$method_name<br/>\n";
}

}
}

$vb =& new codeigniter_bridge($vbulletin);
$vb->postThread();
?>