2005-10-12, 01:20 AM
Here is a tip about globals in functions
If you like to code your mod using functions but you get an error saying something like "Call to a member function on a non-object" then that's where globals come in.
The globals I use are
global $db, $lang, $mybb, $templates, $header, $headerinclude, $theme, $footer;
From my experience..
If it has an arrow after it then it should be called in the globals (ie. $db->query) or if it's used in the template file ($header, $headerinclude, $theme, $footer)
Here's a sample code using a function an globals
I can't exactly explain why it works like that but hopefully someone will shine some light on it.
If you like to code your mod using functions but you get an error saying something like "Call to a member function on a non-object" then that's where globals come in.
The globals I use are
global $db, $lang, $mybb, $templates, $header, $headerinclude, $theme, $footer;
From my experience..
If it has an arrow after it then it should be called in the globals (ie. $db->query) or if it's used in the template file ($header, $headerinclude, $theme, $footer)
Here's a sample code using a function an globals
function test()
{
global $db, $lang, $mybb, $templates, $header, $headerinclude, $theme, $footer;
$mybb->usergroup['cancp'] == "yes")
{
$sometext = $lang->sometext;
}
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."test WHERE testid='".intval($mybb->input['testid'])."'");
$result = $db->fetch_array($query);
eval("\$test = \"".$templates->get("test")."\";");
outputpage($test);
}
I can't exactly explain why it works like that but hopefully someone will shine some light on it.