首页 > 解决方案 > 如何使用php链接目录html文件中的引导文件

问题描述

我有一个头文件,其中包含指向 Bootstrap 和 jQuery 的链接。我在我的索引文件和我的常见问题解答文件中都包含了这个标题。索引文件中的链接工作正常,但 FAQ 文件中的引导链接不起作用。

我的头文件:

<head>
    <title><?php echo $title; ?></title>
    <link rel="stylesheet" type="text/css" href="./bootstrap.css">

    <link rel="stylesheet" type="text/css" href=".././style.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
    
    <link rel="stylesheet" href=".././../jQuery/jquery-ui.css">
        <script type="text/javascript" src=".././../jQuery/jquery-3.4.1.js"></script>
        <script type="text/javascript" src=".././../jQuery/jquery-ui.js"></script>
</head>

这是我的索引文件,其中包含标题:

<?php
$title = "Home page";                   // (1) Set the title
include "header.php";                 // (2) Include the header
?>

这是我的常见问题解答文件,其中还包括标题:

<?php
$title = "Home page";                   // (1) Set the title
include "../header.php";                 // (2) Include the header
?>

这是我的目录的快照:

根目录 前端目录

标签: phphtml

解决方案


我认为这是因为您的相对路径,例如:

.././../jQuery/jquery-ui.js

您应该将它们更改为绝对路径,它可以解决您的问题
例如更改为这样的:

<script type="text/javascript" src="<?php echo __DIR__ ?>/../../jQuery/jquery-ui.js"></script>

推荐阅读