问题描述
首先,对不起英语语法,而不是我的母语。
在开始之前,我想澄清一下,我是在称为Admin SB 2的boostrap 4模板中实现所有这些功能的。
在这个小项目中,在我的主文件夹中,我有index.php文件,在我的项目文件夹中,我有一个名为 views 的目录,在该目录中有footer.php和header.php index.php我包括footer.php和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 -->
要求将产生致命错误(E_COMPILE_ERROR)并停止脚本。
包含只会产生警告(E_WARNING),脚本将继续
因此,如果希望继续执行并向用户显示输出,即使缺少include文件,也请使用include语句。