我已经搜索了一个可以在多个项目中使用的一站式修复,但我还没有发现任何工作。
因此,当我构建一个站点时,我使用PHP包括站点中使用的站点的头部,导航和页脚。
所以对于包含标题,导航,正文和页脚的模板文件,我这样做:
<?php include 'views/headerHTML.php'; ?> <?php include 'views/headerNav.php'; ?> <div id="main"> <!--content--> </div><!--main--> <?php include 'views/footer.php'; ?>现在我的CSS调用行与任何JS或跟踪片段一起位于headerHTML中。
如果网页位于多个文件夹中 - 则包含必须相对于根文件进行更改
<?php include '../../views/headerHTML.php; ?>但其中的CSS和JS引用随后变得不正确,因为它是相对于ROOT编写的
<link type="text/css" rel="stylesheet" href="css/test.css" />我将WAMP用于本地,我的所有项目都基于具有多个提供程序的共享虚拟服务器(GD,fatcow等),并且它们都有自己的古怪根引用等。
我试图使用诸如此类的解决方案
$_SERVER['DOCUMENT_ROOT'] define('ROOT', dirname(__FILE__));但我似乎无法让他们在我的本地服务器和他们的虚拟服务器上工作。 我想要的是,无论我的网页在文件夹层内的深度如何 - 标题中的引用,导航,页脚,参考代码片段或位于各自文件夹中的工具都将被正确调用。
我一直在做的是设置特定的包含,其中的引用更改为工作,所以:
<?php include '../../views/headerHTML_DoubleFolder.php; ?>这适用于两个文件夹深的页面。
我100%肯定这可能是我能做的最糟糕的事情,并且首先否定了做包含的目的
有人愚弄我,教我一些新的东西= D!
我很感激。
编辑---------------
问题的例子=
localhost / site / login / login.php调用:
<?php include '../views/headerHTML.php'; ?>在该headerHTML.php文件中有:
<link type="text/css" rel="stylesheet" href="css/style_v0313.css" />正如您所看到的,当login.php通过headerHTML调用它时,css位置将不正确
在访问login.php时,将/或./或dirname( FILE )添加到css href仍然不会加载样式表
I have searched for a one stop fix I can use across multiple projects but i haven't found anything to work quite yet.
So when I build a site, i use PHP includes for the headers, nav, and footer of site that are used across the site.
so for a template file that will include the header, nav, body, and footer, i do:
<?php include 'views/headerHTML.php'; ?> <?php include 'views/headerNav.php'; ?> <div id="main"> <!--content--> </div><!--main--> <?php include 'views/footer.php'; ?>Now my CSS call lines are located in the headerHTML along with any JS or tracking snippets.
if a webpage is located within multiple folders - then the includes have to change relative to the root files
<?php include '../../views/headerHTML.php; ?>but the CSS & JS references within that include then becomes incorrect as it is written relative to ROOT
<link type="text/css" rel="stylesheet" href="css/test.css" />I use WAMP for local and all my projects are based on shared virtual servers with multiple providers (GD, fatcow, etc.) and they all have their own wacky root references and such.
I tried to use solutions such as
$_SERVER['DOCUMENT_ROOT'] define('ROOT', dirname(__FILE__));But i cant seem to get them to work across my local server and their virtual servers. All i want is that no matter how deep my webpage is within the folder heirarchy - the references within the header, nav, footer that reference code snippets or utils that are located in their respective folders will properly be called.
What i have been doing is setting specific includes that have the references within them changed to work so:
<?php include '../../views/headerHTML_DoubleFolder.php; ?>Which is meant for a page that is two folders deep.
I am 100% sure that is probably the worst thing i can do and negates the purpose of doing includes in the first place
Someone make a fool of me and teach me something new please =D !
I appreciate it.
EDIT ---------------
Example of the problem =
localhost/site/login/login.php calls:
<?php include '../views/headerHTML.php'; ?>And within that headerHTML.php file there is:
<link type="text/css" rel="stylesheet" href="css/style_v0313.css" />And as you can see the css location will not be correct when the login.php calls it via the headerHTML
adding / or ./ or dirname(FILE) to the css href still will not load the style sheet when visiting login.php
最满意答案
您可以使用路径,例如/css/style.css。
You can use paths, like /css/style.css.
更多推荐
发布评论