This question already has an answer here:
can someone please help, im getting this error:
Fatal error: Call to undefined method stdClass::AddFile() in C:\xampp\htdocs\index.php on line 8
***UPDATE This is NEW my index.php:
<?php
define('IN_INDEX', 1);
include ('inc.php');
$TPL = new CoreScript_TPL();
$TPL->TPLDir = 'themes/'.$hotel[temp].'';
if(!isset($_GET['page']) || $_GET['page'] == 'index') {
$TPL->AddFile('index');
}
echo $TPL->Run();
?>
The inc.php contains some includes, to the config, a class.template.php and my core.tpl.php, witch is this:
<?php
class CoreScript_TPL {
public $TPLData;
public $TPLDir;
public $TPLVars = array();
function AddFile($FileName) {
if(file_exists($this->TPLDir . '/' . $FileName . '.tpl')) {
$this->TPLData .= file_get_contents($this->TPLDir . '/' . $FileName . '.tpl');
return true;
}
else
return false;
}
function AssignVar($Variable, $Value) {
$this->TPLVars[$Variable] = $Value;
}
function Run() {
$OutputData = $this->TPLData;
foreach($this->TPLVars as $key => $value) {
$OutputData = str_replace('{'.$key . '}', $value, $OutputData);
}
return $OutputData;
}
}
?>
What is needs to do is request the theme name from the config.php and show that theme.. But it doesn't... Can someone please help??
By the way, sorry for my bad english, i'm dutch....
Thanks,
Wesley Peeters
**UPDATE:
my class.template.php
if (!empty($TPL)) {
//Dingen die met het hotel te maken hebben
$TPL->setParameter('longname', $_CONFIG['hotel']['longname']);
$TPL->setParameter('shortname', $_CONFIG['hotel']['shortname']);
$TPL->setParameter('theme', $_CONFIG['hotel']['template']);
$TPL->setParameter('ip', $_CONFIG['hotel']['ip']);
$TPL->setParameter('build', $_CONFIG['hotel']['webbuild']);
$TPL->TPLDir = 'themes/'.$theme.'';
//Dingen die met SWF's te maken hebben
$TPL->setParameter('ext_vars', $_CONFIG['swf']['externalvars']);
$TPL->setParameter('productdata', $_CONFIG['swf']['productdata']);
$TPL->setParameter('furnidata', $_CONFIG['swf']['furnidata']);
$TPL->setParameter('external_texts', $_CONFIG['swf']['externaltexts']);
$TPL->setParameter('swfpath', $_CONFIG['swf']['path']);
//Overige
$TPL->setParameter('twitteruser', $_CONFIG['social']['twitter']);
$TPL->setParameter('fbuser', $_CONFIG['social']['facebook']);
}
</div>
You're missing the line to create $TPL
as an instance of CoreScript_TPL:
$TPL = new CoreScript_TPL();
Without that, when you do $TPL->TPLDir = ...
, PHP will create $TPL
as a new, empty "stdClass" object, which won't have an AddFile
method.