【发布时间】:2011-12-10 13:51:08
【问题描述】:
我在 php 中遇到了输出缓冲的奇怪问题。使用此代码,我在尝试要求第一个文件后收到意外的 $end 错误。 (在本例中为 /header.php)这是我的代码的设置方式:
class View
{
function __construct()
{
ob_start();
$this->page();
ob_end_flush();
}
private function rekwire($filename)
{
if(file_exists(APPPATH.$filename)) require(APPPATH.$filename);
else if(file_exists(BASEPATH.$filename)) require(BASEPATH.$filename);
}
private function page()
{
$this->rekwire('/header.php');
$this->rekwire('/page.php');
$this->rekwire('/footer.php');
}
}
这种结构在我的虚拟主机上对我有用。我最近在设置本地测试服务器 (WAMP) 时才遇到问题,这让我认为它可能是 php 或 apache 的设置。任何帮助表示赞赏!
【问题讨论】:
-
我认为你实际上可以调用你的方法
require,因为它是一个类成员,而不是一个全局函数,所以你不应该有任何冲突。