0

このコードを使用してマスター テンプレート内のコンテンツ ページをレンダリングする PHP サイトがあります。

function render($template, $vars = array(), $supertemplates = array()) {
  if (is_array($vars)) extract($vars);  // Extract the vars to local namespace
  else $content = $vars;
  ob_start();                    // Start output buffering
  include($template.'.tpl.php'); // Include the file
  $content = ob_get_contents();  // Get the content of the buffer
  ob_end_clean();                // End buffering and discard
  foreach ($supertemplates as $supertemplate)
  $content = render($supertemplate, array('content' => $content));
  return $content;               // Return the content
}

アプリケーション自体は、(サイトのルートにある) 巨大なファイル index.php であり、引数を取り、適切な関数を実行するルーターを備えています。

これがリスト機能です

function list() {
    //Get some data from the database ($data)
    print render('templates/_list', array('data' => $data), array('templates/master'));
    exit;
}

リスト テンプレートは、別のテンプレートを自身の内部にレンダリングします。しかし、現在ブラウザに送信される唯一の html はリスト テンプレートであり、マスター テンプレートはブラウザに送信されることさえありません。これは以前に数回見たことがありますが、通常はブラウザを更新すると消えます。

なぜこれが起こっているのか分かりますか?これはすべてではなく一部のテンプレートでのみ発生しますが、機能するページと機能しないページに大きな違いがあるとは思わないため、その理由を見つけることができませんでした。

4

0 に答える 0