我的php包含有问题,我想知道是否有人能知道我的代码可能出了什么问题。这就是我的文件集是如何被分解的。
我有两个索引文件。一个在bank\index.php,一个在bank\onlinebanking\index.php。
我已经将我的页眉和页脚分割成两个不同的文件。他们被列为bank\header.inc.php和bank\footer.inc.php。我捕获我的css从我的标题为整个网站。
标题包括:
<!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" />
<title>Banking Home Page</title>
</head>
<body class="body">
<link href="../_assets/stylesheets/style.css" rel="stylesheet" type="text/css" />
<div>
<table border="0" width="100%" cellspacing="0" cellpadding="0" background="_assets/images/bkrnd_top.png">
<tr>
<td width="50%"><img border="0" src="../_assets/images/bkgrnd_tl.png" width="205" height="61"></td>
<td width="50%">
<p align="right"><img border="0" src="../_assets/images/logo.png" width="160" height="61"></td>
</tr>
</table>
</div>
<div>
<table border="0" width="100%" cellspacing="1" cellpadding="0" background="_assets/images/background_headerarea.png">
<tr>
<td width="100%"><font face="Arial" size="2"><b> <font color="#FFFFFF">HOME | TBA | TBA | TBA | TBA | TBA</font></b></font></td>
<td>
</tr>
</table>
<?php require_once('login.inc.php'); ?>
我遇到的问题是我无法让我的css或_assets为我的两个inex文件正确地呈现。
如果我将链接更改为类似于src=的“./_资产/映像/bkgrnd_tl.png”,它将在bank\onlinebanking\index.php中正确显示,但不会在bank\index.php中显示。如果我将链接更改为src=“_assets/映像/bkgrnd_tl.png”,它将显示在bank\index.php中,而不是在bank\onlinebanking\index.php中。
我希望你明白我想说的话。我希望只有一个页眉和页脚的所有css渲染在所有页面。
我的包括如下:
bank\onlinebanking\index.php =
require\_once('../websiteconfig.inc.php'); require\_once('../header.inc.php'); ?>
bank\index.php
发布于 2012-02-07 03:11:38
设置一些路径变量可能会对您有所帮助。然后,您可以为您的所有图像和css提供一个绝对路径。类似于:
define("PATH", "http://www.mysite.com");
然后你就可以做这样的事情:
<img border="0" src="<?php echo PATH; ?>/_assets/images/bkgrnd_tl.png" width="205" height="61">
您也可以设置多个导致不同区域的路径,例如主题路径。
发布于 2012-02-07 04:54:08
样式表链接应该包括在标题部分,如下所示
<head>
<link href="../_assets/stylesheets/style.css" rel="stylesheet" type="text/css" />
</head>
发布于 2012-02-07 05:06:35
您遇到的问题很简单,您的各种文件的路径是不同的。例如:
home_directory/bank/index.php
home_directory/bank/onlinebanking/index.php
"..“你的链接路径中有一部分写着“去一个更高的层次”。
但是,对于上面将转到home_directory/
的第一个文件,对于第二个文件,它将转到home_directory/bank
。
你有两个潜在的解决方案。一种方法是将所有代码文件移动到相同的目录深度。例如:
home_directory/bank/index.php
home_directory/onlinebanking/index.php
第二个,也可能是更好的方法,是通过根相对平移来引用您的附加工件。换句话说,与其使用../whatever
,不如使用/whatever
在您的例子中,应该是:href="/_assets/stylesheets/style.css"
https://stackoverflow.com/questions/9170471
复制相似问题