이것은 내 마음이 꼬인 것입니다. 분명히 PHP는 문제가 있음을 알기도 전에 미리 처리 할 수 없습니다.문자열을 HTML 헤더에 에코하기
나는 문서의 머리글이있어 :
<? $site = new core();
register_shutdown_function(shutdown);
echo $site->insert_to_header(); ?>
을 그리고 더 아래, 의도적으로 넣어 :
echo $test;
경고를 만들려면. 이것은 그 다음과 같습니다, shutdown();
로 이동됩니다 :
class core {
function shutdown() {
$a = error_get_last();
if ($a == null) {
echo "No errors";
} else {
core::insert_to_header_cache('<link rel="stylesheet" href="core.css" type="text/css" />');
core::insert_to_body_cache('<div class="error-handler"><h3>Error!</h3>
<br/>Error type: <strong>' . $a[type] . '</strong>
<br/>Error message: <strong>' . $a[message] . '</strong>
<br/>Located in: <strong>' . $a[file] . '</strong>
<br/>Line: <strong>' . $a[line] . '</strong>
</div>');
}
}
//TODO Teleport variables to here, without doing that beforehand, this whole thing is broken :(
function insert_to_header_cache($insertion ='') {
$headercache += $insertion . '/n';
return true;
}
function insert_to_body_cache($insertion ='') {
$bodycache += $insertion . '/n';
return true;
}
function insert_to_header() {
global $headercache;
echo $headercache;
return true;
}
function insert_to_body() {
global $bodycache;
return $bodycache;
}
}
내 문제는 그 시점을지나 이미 때, 어떻게 헤더로 다시 출력으로 내 insert_to_header_cache
기능을 얻을 수있다?
글로벌 $bodycache
및 $headercache
이 작동하지 않는다는 점을 명심하십시오. 그러나 여기에는 문제가 없습니다. 사전에 아무 것도 울리지 않으면 작동하지 않습니다. 질서 때문에 나는 그 정도를 압니다. 사전에
감사합니다,
에반 해리슨은
대신, 컨트롤러 내에서 echo's'peppering 당신의 처리가 완료되면, 오직 맨 끝에 출력에 각 블록을 당신의 모든 기능을 호출하지 시작할 수 있습니다. –
나는 그들이 작업하는 동안 진행되고있는 일들을보기 위해 그 곳곳으로 피가 .다. –
이것이 제가 말하고자하는 것입니다 : http://codepad.org/Ny3Zxk5L 참고로, 이것은 매우 단순한 예입니다. 그러나 전반적인 개념은 같습니다. –