【发布时间】:2011-11-06 05:00:37
【问题描述】:
未定义的常量问题不是一个新问题,我已经尝试过 Google,发现有一百万个答案涉及缺少引号的数组,这不是我的解决方案。我正在学习使用 PHP 进行 OOP 编码,这实际上是我使用它的最初几个小时。这是我创建的类。
class template {
var $page;
function __construct() {
$this->page = 'home';
}
function getHeader($header = 'header') {
include ('template/'.$header.'.php');
}
function getFooter($footer = 'footer') {
include ('template/'.$footer.'.php');
}
function setPage($page = 'home') {
$this->page = $page;
}
function getPage() {
if(page === 'home') {
include('template/home.php');
} else {
include('template/'.$this->page.'.php');
}
}
}
这就是我实例化它的方式。
include('class.template.php');
$template = new template();
$template->getHeader();
if(isset($_GET['page'])) {
$template->setPage($_GET['page']);
}
$template->getPage();
$template->getFooter();
当然还有错误 - 注意:使用未定义的常量页面 - 在第 24 行的 /Applications/MAMP/htdocs/titan-up/class.template.php 中假定为“页面”
这显然是我应该立即发现的,我做错了,但为时已晚,我不知所措。非常感谢任何帮助。
编辑:任何使学习过程更容易的链接将不胜感激。我已经在阅读它的 PHP 手册,并且在 PHP 方面有很强的背景,但不是 OOP。
【问题讨论】: