致命错误:在第8行的C:\ xampp \ htdocs \ index.php中调用未定义的方法stdClass :: AddFile()

时间:2013-11-03 13:46:20

标签: php

有人可以帮忙,我得到这个错误:

Fatal error: Call to undefined method stdClass::AddFile() in C:\xampp\htdocs\index.php on line 8

*** UPDATE 这是我的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();

?>

inc.php包含一些include,包括一个class.template.php和我的core.tpl.php,这就是:

<?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;
    }

}
 ?>

需要做的是从config.php请求主题名称并显示该主题.. 但它不...... 有人可以帮忙吗?

顺便说一句,抱歉我的英语不好,我是荷兰人......

谢谢,

Wesley Peeters

**更新:

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



}

1 个答案:

答案 0 :(得分:1)

您错过了创建$TPL作为CoreScript_TPL实例的行:

$TPL = new CoreScript_TPL();

如果不这样做,当你执行$TPL->TPLDir = ...时,PHP将创建$TPL作为一个新的空“stdClass”对象,它不会有AddFile方法。