[英]Variable auto_prepend_file?
好的,我很想提出我的問題XD如果有人有更好的標題,請編輯!
無論如何,我在php.ini文件中有此文件:
auto_prepend_file = ./include/startup.php
auto_append_file = ./include/shutdown.php
startup.php看起來像這樣:
<?php
chdir(__DIR__."/..");
require("include/db.php");
// more setup stuff here
if( $_SERVER['REQUEST_METHOD'] == "AJAX") { // yup, custom HTTP method :p
// parse file_get_contents("php://input")
}
else {
$output_footer = true;
require("include/header.php");
}
shutdown.php是這樣的:
<?php
if( isset($output_footer)) require("include/footer.php");
現在,討論主要問題。
header.php包含<title>My shiny new site</title>
。 我希望標題取決於當前正在查看的頁面。 目前,我有一些涉及JavaScript的丑陋技巧:
document.title = document.getElementsByTagName('h1')[0].textContent;
顯然,這並不理想! 關於由於auto_prepend_file而輸出所述標題時如何調整標題的任何建議?
我不認為您應該使用諸如此類的添加和添加功能,但這只是我的觀點。
為什么不創建header.php
以允許使用可變標題文本。 並完全刪除前置和追加腳本
<title><?php echo (isset($title)) ? $title : 'default title'; ?></title>
並且每當您需要標題標簽時。
$title = "some title";
require("include/header.php");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.