The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Using $vbulletin or $db in non-vb powered php file?
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) Code:
$templater = vB_Template::create('customTemplate'); $templatevalues['customTemplate_show'] = $templater->render(); vB_Template::preRegister('header', $templatevalues); (hook: parse_templates) Code:
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); The PHP file is simply: Code:
<?php echo("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: Code:
$result = $db->query_read("Select * from ".TABLE_PREFIX."myTable"); 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. |
#2
|
||||
|
||||
$db->query_read is defined by vbulletin. If you don't include global.php (or init.php), then it isn't defined. You would have to use standard mysql if you aren't going to include the vbulletin files that allows you to use query_read.
|
#3
|
|||
|
|||
Thanks a lot Lynne, init.php did the trick for me.
The posts I read mostly said to add global.php but in my case that introduced a recursive call to the header template. (which eventually crashed the browser). Incase anyone is reading, I needed to add the following right at the top of myPHPfile.php to get things working: Code:
define('VB_AREA', 'Forum'); define('THIS_SCRIPT', 'myPHPfile'); require_once("./includes/init.php"); |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|