我在整个项目中使用了以下内容,直到现在还没有注意到问题:
include '../titleBar.php';
require_once '../navBar.php';
require_once '../theDatabase.php'; // functions for the UI and DB access
require_once '../globals.php'; // variables and statics used throughout
以上内容已经运行了3周。原因../在文件名为之前:上面的语句出现在特定于用户的文件(如FOO_x.php)中的用户子文件夹中,这些文件特定于用户输入的数据——只有上面的include和require_one文件涉及公共代码,公共代码是根网站目录中子文件夹上方的一个目录。
所以我添加了这个新的代码,它没有拉入样式表:
include '../titleBar.php';
require_once '../navBar.php';
require_once '../theDatabase.php';
require_once '../globals.php';
<html>
<head>
<link rel="stylesheet" type="text/css" href="../globalStyles.css" />
我把它改成这样,样式表被拉到用户特定的文件FOO_x.php:中
<link rel="stylesheet" type="text/css" href="globalStyles.css" />
牢记——上面的链接rel位于根网站的子目录中的文件FOO_x.php中。AND--文件"globalStyles.css"不在FOO_x.php所在的子目录中。
文件"globalStyles.css"比包含FOO_x.php.的文件夹高一级
那么,href=globalStyles.css为什么/怎么能工作呢?的确如此。
因为在过去的3周里,FOO_x.php顶部的include/request列表中的第二个文件"navBar.php"其中包含以下声明:
<base href='http://localhost/theSiteRootFolder/'></base>
所以当我尝试时
<link rel="stylesheet" type="text/css" href="../globalStyles.css" />
FOO_x.php页面上没有出现任何样式,我将其切换为
<link rel="stylesheet" type="text/css" href="globalStyles.css" />
突然出现了各种风格。然后我想起"很久以前"我会说"基本"在navBar.php中。
接下来我想"好吧,如果link-rel语句使用navBar.php中的‘base’语句——则Database.php和globals.php文件的require_one不需要../任何一个毕竟,这两个文件出现在require_once navBar.php中的"base"语句之后link-rel语句确实如此。"(对我来说)合乎逻辑。
因此,我将文件FOO_x.php的顶部更改为:
include '../titleBar.php';
require_once '../navBar.php';
// these next 2 file 'requires' should work -- the navBar.php declared a 'base' to be the folder above this one
require_once 'theDatabase.php';
require_once 'globals.php';
我想"一旦navBar.php被拉入其基本声明,因为显然链接rel坚持globalStyles.css不能具有../--则数据库.php或全局.php.都不应该
因为这3个语句都出现在'base'语句的href='之后http://localhost/theSiteRootFolder相对路径根。
然而,只有链接rel在navBar.php中"尊重"或关注上面声明的"基本"声明。
为什么?我不明白为什么,因为navBar.php建立了所有相对路径解析的"基础"--为什么这不起作用:
<link rel="stylesheet" type="text/css" href="../globalStyles.css" />
但这些工作还好吗?
include '../titleBar.php';
require_once '../navBar.php';
// okay the 'base' was just established yet I still have to do this:
require_once '../theDatabase.php';
require_once '../globals.php';
PHP解析器不解析HTML。它只解析<?php ?>
标记之间的内容。基本上,<base>
标签对PHP来说毫无意义。
我建议你不要使用<base>
,因为我从未见过使用它的理由。