私のページは 4 つのセクションに分割されており、各セクションは php オブジェクトのメソッドによって生成されます。
最初のセクションはテキストのみを表示し、うまく機能します。2 番目と 4 番目のセクションは何も表示されません (今のところ)。
私の問題は、埋め込まれた Google スプレッドシートを表示することになっている 3 番目のセクションにあります。
PHP ページは正しい html コードを作成します。実際、タイトル テキストは正しく表示されますが、iframe には、要求されたファイルが存在しないという Google からのメッセージが表示されます。
次に、Ctrl+U を押してページ ソース (私は Firefox を使用しています) を開き、テキストをコピーして新しい test.html に貼り付け、サーバーに保存し、Firefox で新しい test.html を開き、Google でそれが好きで、iframe が正しく表示されます。
ソースが同じページが 2 つあるのに、一方が機能し、もう一方が機能しないのはなぜですか?
このページの完全な php コードは次のとおりです。
<?php
$filename = "parameters-test.txt";
$file_size = filesize($filename);
$handle = fopen($filename, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = str_replace('\"', '"', $content); // ??? why do I need this? And do I need only this? Isn't there some decode function?
$alldata = json_decode($content);
$pages = $alldata->page;
$parameters = $alldata->parameters[0];
$websiteTitle = $parameters->websiteTitle;
$sheets = array();
foreach($pages as $page) {
$sheet = new Sheet();
$sheet->load($page);
array_push($sheets, $sheet);
}
if(isset($_GET["pageId"])) $currentSheet = $_GET["pageId"];
else $currentSheet = 0; // this is the Welcome page
class Sheet {
public $definition = '';
public function load($parameters) {
$this->definition = $parameters;
}
public function showTitle() {
echo '<h1>';
echo $this->definition->title;
echo '</h1>';
echo "\n";
}
public function showHeader() {
if($this->definition->heightHeader) {
echo '<iframe width="';
echo $this->definition->width;
echo '" height="';
echo $this->definition->heightHeader;
echo '" frameborder="0" src="https://docs.google.com/spreadsheet/pub?key=';
echo $this->definition->documentId;
echo '&single=true&gid=';
echo $this->definition->headerSheetId;
echo '&output=html&widget=false&gridlines=false&range=';
echo str_replace(':', '%3AD', $this->definition->rangeHeader);
echo '"></iframe><br />';
echo "\n";
}
}
public function showBody() {
echo '<iframe width="';
echo $this->definition->width;
echo '" height="';
echo $this->definition->heightBody;
echo '" frameborder="0" src="https://docs.google.com/spreadsheet/pub?key=';
echo $this->definition->documentId;
echo '&single=true&gid=';
echo $this->definition->bodySheetId;
echo '&output=html&widget=false&gridlines=false&range=';
echo str_replace(':', '%3AD', $this->definition->rangeBody);
echo '"></iframe><br />';
echo "\n";
}
public function showLinks() {
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="index.css" />
<title><?php echo $websiteTitle; ?></title>
</head>
<body>
<?php
$sheets[$currentSheet]->showTitle();
$sheets[$currentSheet]->showHeader();
$sheets[$currentSheet]->showBody();
$sheets[$currentSheet]->showLinks();
?>
</body>
</html>
そして、生成された html は次のとおりです。これは、test.php からではなく、test.html から取得された場合にのみ機能します。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="index.css" />
<title>this is the title</title>
</head>
<body>
<h1>Hotshots pool league</h1>
<iframe width="500" height="300" frameborder="0" src="https://docs.google.com/spreadsheet/pub?key=0AqEyi7du69LQdHRJXzViMlhEdHVYY2E4X1hnZ21EQ2c&single=true&gid=12&output=html&widget=false&gridlines=false&range=A1%3ADZ999"></iframe><br />
</body>
</html>