saajjj
01-01-2010, 11:43 AM
Hello,
This post seems to have grown. I wanted to explain exactly what I was doing so that someone might point me in the right direction.
I've made a custom template inside which I want to output from a PHP file.
This customTemplate is itself used inside the header template. The plugin for this customTemplate looks like:
(hook: parse_templates)
$templater = vB_Template::create('customTemplate');
$templatevalues['customTemplate_show'] = $templater->render();
vB_Template::preRegister('header', $templatevalues);
The plugin I'm using to enable me to write from the PHP file is:
(hook: parse_templates)
ob_start();
include("http://www.myforum.com/myPHPfile.php");
$contents = ob_get_contents();
ob_end_clean();
$preRegister['phpFile_output'] = $contents;
vB_Template::preRegister('customTemplate', $preRegister);
So, the forum header has {vb:raw customTemplate_show} and customTemplate has {vb:raw phpFile_output}
The PHP file is simply:
<?php
echo("hello world");
?>
The above works as expected. i.e in the header I can see 'hello world'.
My problem starts when I want to start using vB specific globals in myPHPFile.php like $vbulletin or $db. I get a:
Fatal error: Call to a member function query_read() on a non-object in /home/xxxx/public_html/myPHPFile.php on line 9
where line 9 is:
$result = $db->query_read("Select * from ".TABLE_PREFIX."myTable");
My understanding is that this error means that $db is not an object that PHP recognizes. This led me to try out various things, none of which worked. I tried adding the following to the start of myPHPfile.php:
1. require_once("./global.php"); <--- this starts an infinite loop, and eventually crashes the browser
2. global $vbulletin
3. global $db
I'd like to point out that, thanks to articles posted here, I have been able to use $vbulletin and $db in a regular vb powered custom page without any issues.
Any help appreciated.
This post seems to have grown. I wanted to explain exactly what I was doing so that someone might point me in the right direction.
I've made a custom template inside which I want to output from a PHP file.
This customTemplate is itself used inside the header template. The plugin for this customTemplate looks like:
(hook: parse_templates)
$templater = vB_Template::create('customTemplate');
$templatevalues['customTemplate_show'] = $templater->render();
vB_Template::preRegister('header', $templatevalues);
The plugin I'm using to enable me to write from the PHP file is:
(hook: parse_templates)
ob_start();
include("http://www.myforum.com/myPHPfile.php");
$contents = ob_get_contents();
ob_end_clean();
$preRegister['phpFile_output'] = $contents;
vB_Template::preRegister('customTemplate', $preRegister);
So, the forum header has {vb:raw customTemplate_show} and customTemplate has {vb:raw phpFile_output}
The PHP file is simply:
<?php
echo("hello world");
?>
The above works as expected. i.e in the header I can see 'hello world'.
My problem starts when I want to start using vB specific globals in myPHPFile.php like $vbulletin or $db. I get a:
Fatal error: Call to a member function query_read() on a non-object in /home/xxxx/public_html/myPHPFile.php on line 9
where line 9 is:
$result = $db->query_read("Select * from ".TABLE_PREFIX."myTable");
My understanding is that this error means that $db is not an object that PHP recognizes. This led me to try out various things, none of which worked. I tried adding the following to the start of myPHPfile.php:
1. require_once("./global.php"); <--- this starts an infinite loop, and eventually crashes the browser
2. global $vbulletin
3. global $db
I'd like to point out that, thanks to articles posted here, I have been able to use $vbulletin and $db in a regular vb powered custom page without any issues.
Any help appreciated.