MVC框架中的标准做法是使用
output buffering(ob_start(),ob_get_contents()和ob_end_clean())来控制发送给用户的方式,时间和内容.
这样,只要您捕获框架的输出,就不会在您需要之前将其发送给用户.
要加载404,您将使用(例如):
require "config.php";
$page = $_GET['page'];
ob_start();
if (isset($page)) {
echo "isset is true";
if (file_exists(MVCROOT."/$page.php")) {
include MVCROOT."/$page.php";
$output = ob_get_contents();
ob_end_clean();
echo $output;
} else {
ob_end_clean(); //we don't care what was there
header("HTTP/1.0 404 Not Found");
include MVCROOT."/error_404.php"; // or echo a message, etc, etc
}
}
?>
希望有所帮助.