Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从文件夹中调用master.php文件而不丢失所有路径?_Php_Master - Fatal编程技术网

如何从文件夹中调用master.php文件而不丢失所有路径?

如何从文件夹中调用master.php文件而不丢失所有路径?,php,master,Php,Master,我正在用php制作一个网站。为了使页眉和页脚易于更新,我制作了一个master.php文件,其内容如下: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-sca

我正在用php制作一个网站。为了使页眉和页脚易于更新,我制作了一个master.php文件,其内容如下:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../images/a-master-favicon.ico" alt="a-master-favicon" >

    <title>Testing site</title>

    <link href="assets/css/sticky-footer-navbar.css" rel="stylesheet"/>
    <link rel="stylesheet" href="assets/css/head_footer.css" />
  </head>

  <body>

    <?php $signed_request = $_POST['signed_request']; ?>
    <?php if(empty($signed_request)): ?>
        <?php include('header.php'); ?>
    <?php else: ?>
        <div id="eatSpace" style="margin-bottom: -175px;"></div>
    <?php endif; ?>

    <?php include($content); ?>

    <?php if(empty($signed_request)): ?>
        <?php include('footer.php'); ?>
    <?php endif; ?>


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="js/jquery.easing.1.3.js"></script>
    <script src="js/jquery.animate-enhanced.min.js"></script>
  </body>
</html>
所以,当我调用say,index.php时,它看起来是这样的:

<?php

$content = 'index-content.php';
    include('master.php');
这加载一切都很好,只是没有加载css或js,因为主文件中的路径位于不同的目录中。我怎样才能克服这个问题


这是我第一次做这样的事情,所以我不确定我所做的是不是最好的方法。如果你的网站很简单,你可以通过相对链接和绝对链接相结合的方式来解决。您的资源必须使用绝对链接,如所述,而PHP链接可以是相对链接,如所述

然而,它不能很好地扩展到更复杂的应用程序,并且很快就会变得难以管理。现代PHP框架利用了


如果你不喜欢重新发明轮子,学习一个好的框架,比如或。这些用于自动加载和更多功能。

您可以在链接中使用绝对路径,例如,我一定会查看Laravel和Yii,谢谢!
<?php

$content = 'index-content.php';
    include('master.php');
<?php

$content = 'faqs-content.php';
    include('../master.php');