引入文件include
视图中经常会有一些公共部分,例如页头、页尾、侧栏。为了复用,通常我们会把这些做成单独的文件,然后在视图中引用。引入公共视图文件的方法:{include 视图文件名},注意文件大小写。
<!DOCTYPE html>
<head><title>页面标题</title></head>
<body>
{include header} <!-- 引入当前模块下View/header.php文件 -->
{include common/sidebar} <!-- 引入当前模块下View/common/sidebar.php文件 -->
<div>页面的内容</div>
{include common/header|Home} <!-- 引入Home模块下View/common/header.php文件,可以跨模块调用公共视图文件 -->
</body>
</html>
也可以使用原生的方法引入
<!DOCTYPE html>
<head><title>页面标题</title></head>
<?php include common/meta.php?> <!-- 引入当前模块下View/common/meta.php文件 -->
<body>
<?php include common/header.php?> <!-- 引入当前模块下View/common/header.php文件 -->
<div>页面的内容</div>
<?php include common/footer.php?> <!-- 引入当前模块下View/common/footer.php文件 -->
<?php include common/js.php?> <!-- 引入当前模块下View/common/js.php文件 -->
</body>
</html>