链接PHP / HTML的方式 [英] Linking how PHP/HTML

查看:113
本文介绍了链接PHP / HTML的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以即时完成了使用框架的页面,并知道我将我的设计拆分为top.php和bottom.php。在top.php中它链接到style.css和ajax_framework.js等等。现在这很有效,直到我试图包括top.php&在video / index.php(另一个dirr)中的bottom.php,我确实喜欢这样:

Alright so im done doing pages with frames, and know i splitted up my design to top.php and bottom.php. In top.php it's linking to style.css and ajax_framework.js and such.. Now this works great until i tried to include top.php & bottom.php in videos/index.php (another dirr), i did like this:

include "../top.php";
<-- and the originally index.php -->
include "../bottom.php";

现在当我进入网站时,它不会加载style.css,可能是因为它认为风格。 css需要在视频/目录中,同样适用于ajax_framework.js,这两个文件都在父../目录中。

Now when i enter the site, it wont load style.css, probably because it thinks that style.css needs to be in videos/ directory, same goes with ajax_framework.js that are both files are on the parent ../ directory.

现在该怎么办?一些方法或技术可以很好地解决这个问题?所以我不必将style.css和ajax_framework.js复制到我拥有的每个目录中,因为后来如果我想要更改我需要在所有目录中更改的内容,这将是我最后想做的事情..希望你有一些很好的技巧谢谢你

Now what do i do? Some method or technique to solve this in a good way? So i dont have to copy style.css and ajax_framework.js into every directory i have, because then later if i want to change something i would need to change in all directories, which would be my last thing i want to do.. hope you got some nice techniques thank you

推荐答案

你至少有三个选择:


  1. 将所有资源设为URL绝对URL。例如,将< script type =test / javascriptsrc =scripts / foo.js> 更改为< script type = text / javascriptsrc =/ scripts / foo.js> 。如果你能做到这一点,它是迄今为止较少侵入性的解决方案。

  1. Make all your resources URL absolute URL. For instance, change <script type="test/javascript" src="scripts/foo.js"> to <script type="text/javascript" src="/scripts/foo.js">. If you can do it, it's by far the less intrusive solution.

设置 BASEDIR 常数之前你包括 top.php 并制作相对于它的每个资源路径:

Set a BASEDIR constant before you include top.php and make every resource path relative to it:

// in your file that includes top.php
<?php define('BASEDIR', '..'); ?>
// in top.php
<?php if(!defined('BASEDIR')) define('BASEDIR', '.'); ?>
<link rel="stylesheet" type="text/css" href="<?php echo BASEDIR; ?>/style.css"/>


  • 添加< base> < head> 中的HTML标记(这个很糟糕,不要这么做):

  • Add a <base> HTML tag in your <head> (this one sucks, don't do it):

    <base href="/foo"></base>
    <!-- now all srcs, hrefs and whatnot are relative to /foo -->
    

    它很糟糕,因为即使锚点也会相对它。因此,如果您在页面上有< a href =#foo> 这样的链接 qaz.php ,使用< base href =/ bar> ,该链接将指向 / bar#foo 而不是 qaz.php#foo

    Its sucks because even anchors will be relative to it. So if you have a link like <a href="#foo"> on the page qaz.php, with the <base href="/bar">, the link will point to /bar#foo instead of qaz.php#foo.

    这篇关于链接PHP / HTML的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆