我有问题。当我运行我的网站时,模板错误错误。
我得到了这两个错误:
Notice: Undefined variable: template in /home/us22368/domains/******.nl/public_html/index.php on line 4
Fatal error: Call to a member function writePage() on a non-object in /home/us22368/domains/******.nl/public_html/index.php on line 4
一些代码:
的index.php:
<?php
require_once('global.php');
$template->writePage('index');
$template->echoPage();
?>
我的global.php包含这个类(class.template.php):
<?php
if (!class_exists('template')) {
class template {
public $template;
public function writePage($pageName) {
$file = 'app/themes/' . THEME . '/' . $pageName . '.html';
if(!file_exists($file)) {
die('The Page You Asked for does not exist.');
} else {
$this->content .= file_get_contents($file);
}
}
public function echoPage() {
echo $this->content;
}
}
}
?>
有没有人可以帮助我?
答案 0 :(得分:1)
在index.php文件中,您必须创建模板类的实例:
<?php
require_once('global.php');
$template = new template();
$template->writePage('index');
$template->echoPage();
?>
查看php文档:http://www.php.net/manual/en/language.types.object.php