私は最近、CodeIgniter のコードを調べて、それがどのように機能するかを確認しました。
私が理解できないことの 1 つは、CodeIgniter がビューによって生成されたすべての出力を単一の変数に格納し、スクリプトの最後に出力する理由です。
./system/core/Loader.php の 870 行目のコードを次に示します
CI ソース コード @ GitHub
/*
* Flush the buffer... or buff the flusher?
*
* In order to permit views to be nested within
* other views, we need to flush the content back out whenever
* we are beyond the first level of output buffering so that
* it can be seen and included properly by the first included
* template and any subsequent ones. Oy!
*/
if (ob_get_level() > $this->_ci_ob_level + 1)
{
ob_end_flush();
}
else
{
$_ci_CI->output->append_output(ob_get_contents());
@ob_end_clean();
}
関数 append_output は、指定された文字列を CI_Output クラスの変数に追加します。
これを行い、echo ステートメントを使用しない特別な理由はありますか、それとも単なる個人的な好みですか?