如何在我的视图中包含页脚和页眉?

How include footer and header in my views?

首先,抱歉英语语法,不是我的母语。

在开始之前,我想澄清一下,我正在一个名为 Admin SB 2 的 boostrap 4 模板中实现所有这些。

在这个小项目中,在我的主文件夹中,我有我的 index.php 文件,在我的项目文件夹中,我有一个名为 views 的目录,其中我得到了 footer.php and header.php and inside index.php I include footer.php and header.php, 例如:

<?php require_once("views/header.php")?>

<!--START OF MAIN CONTENT -->

<div class = "container">
    <h1> Main content </h1>

</div>
<!-- END OF MAIN CONTENT -->

<?php require_once("views/footer.php")?>

到目前为止一切都很好,问题开始于我的 views 目录中,我有另一个名为 patients 的目录,我计划在该目录中保存与 patients 模块相关的所有内容。我有这个

// header
<? php require_once ("../ header.php")?>
// here goes my content
// footer
<? php require_once ("../ footer.php"); ?>

所以,控制台给我的问题是:

我能理解是页面设计和运行所必需的文件方向错误,但是如果我编辑header.php和footer.php文件中的地址,我可以解决视图中目录内文件的问题,但是 index.php 将停止工作。

你能推荐我做什么?

今天休息愉快

要在页面中包含页眉和页脚文件,请使用 include 语句:

<!--header start -->
    <?php include("includes/header.php"); ?>
<!--header end -->

<div class="container">
</div>


 <!--footer start -->
    <?php include("includes/footer.php"); ?>
 <!--footer end -->

require 将产生致命错误 (E_COMPILE_ERROR) 并停止脚本。

include 只会产生警告 (E_WARNING) 并且脚本会继续

因此,如果您希望继续执行并向用户显示输出,即使包含文件丢失,请使用 include 语句。