好吧,如果有人有更好的标题,请编辑一下我的问题XD。
总之,我的php.ini文件中有这样的内容:
auto_prepend_file = ./include/startup.php
auto_append_file = ./include/shutdown.phpstartup.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输出所述标题时,对如何调整标题有任何建议吗?
发布于 2013-12-12 10:24:06
我认为你不应该像这样使用附加和预置功能,但这只是我的观点。
为什么不创建header.php来允许一个可变标题文本。并完全删除前面的脚本并追加脚本。
<title><?php echo (isset($title)) ? $title : 'default title'; ?></title>每当你需要一个标题标签。
$title = "some title";
require("include/header.php");https://stackoverflow.com/questions/20540658
复制相似问题