我创建了一个Page类,我网站上的所有页面都是该Page类的对象。每个Page对象都有一个title属性,作为参数传递给构造函数,因此创建一个新的Page对象如下所示。使用后的未定义变量require_once
<?php
require_once('library/Page.php');
$page = new Page('About');
$page->header();
这是问题出现的地方。
头()方法是...
public function header()
{
require_once($this->templatePath . 'header.php');
}
然后我使用呼应
<?php echo $page->title; ?>
不过,我得到以下错误页面标题。
通知:未定义 变量:页面在 /Users/aaronfalloon/Projects/PHP/tfm/template/header.php 上线
通知:试图获取非物件 /Users/aaronfalloon/Projects/PHP/tfm/template/header.php 在线
诊断一个我们没有见过的类是很困难的。向我们展示你班上发生了什么事。 – Sampson 2009-12-26 00:38:30