What defines a member to phpBB
Forum rules
Please post any phpBB 3.1.x related topics in the phpBB 3.1.x discussion forum.
Please post any phpBB 3.1.x related topics in the phpBB 3.1.x discussion forum.
Re: What defines a member to phpBB
I can't for the life of me find out which part of the simple template system is interfering. If I comment out phpBB's code in my header, it loads, if I access the page without the template system, it loads. Even the phpBB forum loads and works flawlessly. Might be a long shot, but am I wrong assuming that declaring $template_engine public is the right thing to do? (As seen in my code further up the thread, $template_engine is accessed again through index1.php, but not at the template-file.)
Re: What defines a member to phpBB
Okay, let's see here...I've looked at what you coded, here's a better way to do it.
template.class.php:
That should fix the problem, now that I've inspected the code thoroughly.
template.class.php:
Code: Select all
<?
class Template_Engine
{
// I don't think you need "public $template_engine;"
public $template = ''; // Uhm...undefined var, this should fix the errors. ;)
public function load($filepath)
{
$this->template = file_get_contents($filepath);
}
public function replace($var, $content)
{
$this->template = str_replace("{$var}", $content, $this->template);
}
public function publish()
{
eval("?>".$this->template."<?");
}
}
?>
That should fix the problem, now that I've inspected the code thoroughly.
Re: What defines a member to phpBB
Ok, changed template.class.php to:
And index.php to:
However, I still get the very same error message (Call to a member function sql_query() on a non-object in phpbb3\includes\cache.php on line 51). And, at the top of headers.php, I've still included phpBB's standard way of being included:
Does it make any difference that the cache.php file is the file causing the error? Like, is it because my cache is corrupt, or am I barking at the wrong tree?
Code: Select all
<?
class Template_Engine
{
public $template = '';
public function load($filepath)
{
$this->template = file_get_contents($filepath);
}
public function replace($var, $content)
{
$this->template = str_replace("{$var}", $content, $this->template);
}
public function publish()
{
eval("?>".$this->template."<?");
}
}
?>
And index.php to:
Code: Select all
<?
include ('template.class.php');
$template = new Template_engine;
$template->load("template.html");
$template->replace("{jall}", "<? PostNews(); ?>");
$template->publish();
?>
However, I still get the very same error message (Call to a member function sql_query() on a non-object in phpbb3\includes\cache.php on line 51). And, at the top of headers.php, I've still included phpBB's standard way of being included:
Code: Select all
<?php
define('IN_PHPBB', true);
$phpbb_root_path = './phpbb3/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();
?>
Does it make any difference that the cache.php file is the file causing the error? Like, is it because my cache is corrupt, or am I barking at the wrong tree?
Re: What defines a member to phpBB
You must be overwriting $db in one of the included variables of the template. It could be headers.php, navigation.php, modules/menu/*, modules/footer.html...
Donate to phpBBModders.net - we're poor!
Re: What defines a member to phpBB
Thing is, that if I disable the template, and just put the replacement value instead of the replacement key (PostNews() instead of {jall}) into template.html (and rename it to .php), it returns completely, regardless of included files. And the template-system does not contain $db.
Is the template-system then creating/activating a variable named $db somewhere? I could not find any variable named $db anywhere in my files, nor can I recall using it (I use $dbh for connecting to MySQL, and $result for output).
Is the template-system then creating/activating a variable named $db somewhere? I could not find any variable named $db anywhere in my files, nor can I recall using it (I use $dbh for connecting to MySQL, and $result for output).
Re: What defines a member to phpBB
Gingah wrote:Thing is, that if I disable the template, and just put the replacement value instead of the replacement key (PostNews() instead of {jall}) into template.html (and rename it to .php), it returns completely, regardless of included files. And the template-system does not contain $db.
Is the template-system then creating/activating a variable named $db somewhere? I could not find any variable named $db anywhere in my files, nor can I recall using it (I use $dbh for connecting to MySQL, and $result for output).
Hmm. I'm not sure, but aside from that I do see that you're overwriting the $template variable that phpBB uses for its template system...
Gingah wrote:I had a tought when I woke up: Is it possible that the MySQL connections are interfering with each other? The site and phpBB are running different databases, and different connections (phpBB uses $sql, the site uses $dbh) and neither are closed until at the end of the site.
Wait a minute. Do you mean you changed the $db object in phpBB to use the $sql variable?
EDIT: Can you possibly get a backtrace for this?
Code: Select all
#
#-----[ OPEN ]------------------------------------------
#
includes/cache.php
#
#-----[ FIND ]------------------------------------------
#
$config = $cached_config = array();
#
#-----[ AFTER, ADD ]------------------------------------------
#
// DEBUGGING, REMOVE WHEN DONE
if(defined('IN_TEST'))
{
trigger_error(get_backtrace(), E_USER_ERROR);
}
The partial chunk of code in this function that we're modifying should look like this afterwards:
Code: Select all
$config = $cached_config = array();
// DEBUGGING, REMOVE WHEN DONE
if(defined('IN_TEST'))
{
trigger_error(get_backtrace(), E_USER_ERROR);
}
$sql = 'SELECT config_name, config_value, is_dynamic
FROM ' . CONFIG_TABLE;
$result = $db->sql_query($sql);
Then just edit your other file that you're testing on, and define the constant IN_TEST for a spiffy backtrace. Give it to us when you've got it, this should help the debug process.
Re: What defines a member to phpBB
Just to temporarily avoid killing phpBB's $template, I changed it to this:
template.class.php:
index.php:
And, I defined IN_TEST, and got these results:
Not sure what he is telling me, exactly where does the error occure? It would seem like something is interfering when the cache is getting the config.
template.class.php:
Code: Select all
<?
class Banana_Engine
{
public $banana = '';
public function load_banana($filepath)
{
$this->banana = file_get_contents($filepath);
}
public function replace_banana($var, $content)
{
$this->banana = str_replace("{$var}", $content, $this->banana);
}
public function publish_banana()
{
eval("?>".$this->banana."<?");
}
}
?>
index.php:
Code: Select all
<?
include ('template.class.php');
define("IN_TEST", 1);
$banana = new Banana_engine;
$banana->load_banana("template.html");
$banana->replace_banana("{jall}", "<? PostNews(); ?>");
$banana->publish_banana();
?>
And, I defined IN_TEST, and got these results:
phpBB wrote:General Error
FILE: phpbb3/common.php
LINE: 216
CALL: cache->obtain_config()
FILE: headers.php
LINE: 5
CALL: include('phpbb3/common.php')
FILE: template.class.php(15) : eval()'d code
LINE: 1
CALL: include('headers.php')
FILE: template.class.php
LINE: 15
CALL: eval()
FILE: index1.php
LINE: 7
CALL: Banana_Engine->publish_banana()
Not sure what he is telling me, exactly where does the error occure? It would seem like something is interfering when the cache is getting the config.
Re: What defines a member to phpBB
Okay, I think I know what's up. Took me a bit of thinking, but this has got to be it.
$db is being set in the wrong scope.
When you're running eval(), it's absorbing the scope of where it is called. This sometimes can lead to problems with variables being accessible.
Easiest way is to call eval() in the global scope, take the function out of the class, and write the two files like so:
template.class.php:
index.php:
$db is being set in the wrong scope.
When you're running eval(), it's absorbing the scope of where it is called. This sometimes can lead to problems with variables being accessible.
Easiest way is to call eval() in the global scope, take the function out of the class, and write the two files like so:
template.class.php:
Code: Select all
<?
class Banana_Engine
{
public $banana = '';
public function load_banana($filepath)
{
$this->banana = file_get_contents($filepath);
}
public function replace_banana($var, $content)
{
$this->banana = str_replace("{$var}", $content, $this->banana);
}
}
?>
index.php:
Code: Select all
<?
include ('template.class.php');
define("IN_TEST", 1);
$banana = new Banana_engine;
$banana->load_banana("template.html");
$banana->replace_banana("{jall}", "<? PostNews(); ?>");
eval("?>" . $banana->banana . "<?php");
?>
Re: What defines a member to phpBB
Well put me in a pipe and smoke me! First I got an eval error, but when I replaced <?php with just <? it worked! The site now fully parses the replacement value within the template-system, and outputs as it should, with the phpBB functions.
That's really great man, thanks for the effort to help guys, I wouldn't have managed this on my own
That's really great man, thanks for the effort to help guys, I wouldn't have managed this on my own
Re: What defines a member to phpBB
Gingah wrote:Well put me in a pipe and smoke me! First I got an eval error, but when I replaced <?php with just <? it worked! The site now fully parses the replacement value within the template-system, and outputs as it should, with the phpBB functions.
That's really great man, thanks for the effort to help guys, I wouldn't have managed this on my own
Just as a note, if you use <? instead of <?php, the parser will not execute the code if the short-tags setting is disabled.
Re: What defines a member to phpBB
It is enabled by default, but yes, it's better to keep the <?php. I don't really see how this would solve the problem either...
Donate to phpBBModders.net - we're poor!
Re: What defines a member to phpBB
eviL<3 wrote:It is enabled by default, but yes, it's better to keep the <?php. I don't really see how this would solve the problem either...
I thought I read somewhere that shorttags were disabled by default in PHP 6? Or was that the ASP-style tags that I'm thinking of..
Re: What defines a member to phpBB
Hmmm, so ideally it is preferable to keep it <?php rather than the shorter version? I would, but upon doing so, I get this error:
[quote="Banana Template]Parse error: parse error in index.php(7) : eval()'d code on line 51[/quote]
It works with short tags (eval("?>" . $banana->banana . "<?")), but not with not with full (eval("?>" . $banana->banana . "<?php")).
[quote="Banana Template]Parse error: parse error in index.php(7) : eval()'d code on line 51[/quote]
It works with short tags (eval("?>" . $banana->banana . "<?")), but not with not with full (eval("?>" . $banana->banana . "<?php")).
Re: What defines a member to phpBB
Add a space after <?php.
Donate to phpBBModders.net - we're poor!