致命错误:在第 8 行调用 C:xampphtdocsindex.php 中的未定义方法 stdClass:


Fatal error: Call to undefined method stdClass::AddFile() in C:xampphtdocsindex.php on line 8

有人可以帮忙吗,我收到此错误:

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

***更新这是我的新索引.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包含一些配置的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;
    }
}
 ?>

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

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

谢谢

韦斯利·皮特斯

**更新:

我的类模板.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']);

}

您缺少将$TPL创建为CoreScript_TPL实例的行:

$TPL = new CoreScript_TPL();

没有它,当你做$TPL->TPLDir = ...时,PHP 将创建$TPL作为一个新的、空的"stdClass"对象,它不会有AddFile的方法。