0

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']);



}
  • 2
    You don't show anything creating `$TPL` - does it exist before you try and set a property on it? If not that's the cause. – AD7six Nov 03 '13 at 13:48
  • Wait, i think u mean this, i'll update the post... – user2928643 Nov 03 '13 at 13:49
  • The updated code still shows no call to `$TPL = new CoreScript_TPL()` If you turn on E_STRICT, you ought to be seeing all sorts of warnings about creating a default object from an empty value. – Michael Berkowski Nov 03 '13 at 13:51
  • I put the $TPL = new CoreScript_TPL(); in, now i gust have a whitescreen – user2928643 Nov 03 '13 at 13:54
  • 2
    You _must_ turn on error reporting in development. A white screen means a fatal error. `error_reporting(E_ALL); ini_set('display_errors', 1);` – Michael Berkowski Nov 03 '13 at 13:55
  • @MichaelBerkowski Error reporting was already on, still white screen – user2928643 Nov 03 '13 at 13:58
  • +1 Re-open vote, I don't see this question as a duplicate. Perhaps affecting a small amount of people, but as you can see. It's a call to an exisiting object which has been initialized with the method in place – Daryl Gill Nov 03 '13 at 14:04
  • 2
    I dont see why it should be reopened. The cause is obviously that $TPL is not a CoreScript_TPL object but instead gets initialized as a StdClass in the line after the call to the ctor when assigning the property to it. So the OP needs to find out why the call to `new` doesnt work – Gordon Nov 03 '13 at 14:10

1 Answers1

1

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.

Boann
  • 48,794
  • 16
  • 117
  • 146
  • I don't really get what u mean, where do i put the line? because when i put it into the index.php it just shows me a white screen..... – user2928643 Nov 03 '13 at 13:52
  • @user2928643 You need to do it before you first start using the object. In your case I think that means do it in `class.template.php` after `if(!empty($TPL))`. Make sure you include `core.tpl.php` before `class.template.php`. Although, your class doesn't seem to have a setParameter method..(?) – Boann Nov 03 '13 at 13:55
  • 1
    @user2928643 Maybe that means it's working. – Boann Nov 03 '13 at 14:06
  • @user2928643 there's nothing in the question that adds any output so whitescreen doesn't mean anything specific. – AD7six Nov 05 '13 at 17:36