PHP页面的页面布局模式

时间:2022-02-16 20:07:31

I know a bit about PHP, but never studied in depth, but now I will develop some real sites.

我对PHP有点了解,但从未深入研究过,但现在我将开发一些真正的网站。

One doubt I have is about writing the common HTML elements like Doctype, head and fixed layout like menus or top. I always created a class called Layout to write these parts of the page, and so, in every page, I call the methods of Layout class to build the layout ans basic HTMl elements.

我有一个疑问是编写常见的HTML元素,如Doctype,head和固定布局,如菜单或顶部。我总是创建一个名为Layout的类来编写页面的这些部分,因此,在每个页面中,我都调用Layout类的方法来构建布局和基本的HTMl元素。

My question is if there is another way to do this without the need of call the Layout methods in every page, or maybe, no need for a Layout class. Something like a pattern file with the basic HTML for every page or something like that.

我的问题是,如果有其他方法可以做到这一点,而无需在每个页面中调用Layout方法,或者可能不需要Layout类。类似于每个页面都有基本HTML的模式文件或类似的东西。

So, something like this exists or is needed to put calls in my code to generate the basic HTML content?

那么,在我的代码中调用以生成基本HTML内容时,是否存在或需要这样的东西?

1 个解决方案

#1


1  

Why you're not using template engines? Twig or Smarty. In other case if you don't want to use template engines, you can make document e.g. posts.php and include header.php which contains header data of html

你为什么不使用模板引擎? Twig或Smarty。在其他情况下,如果您不想使用模板引擎,您可以制作文档,例如posts.php并包含header.php,其中包含html的头数据

<?php

include_once('header.php');
// my content
include_once('footer.php');
?>

Header.php

header.php文件

<!doctype html>
<html>
// rest code

#1


1  

Why you're not using template engines? Twig or Smarty. In other case if you don't want to use template engines, you can make document e.g. posts.php and include header.php which contains header data of html

你为什么不使用模板引擎? Twig或Smarty。在其他情况下,如果您不想使用模板引擎,您可以制作文档,例如posts.php并包含header.php,其中包含html的头数据

<?php

include_once('header.php');
// my content
include_once('footer.php');
?>

Header.php

header.php文件

<!doctype html>
<html>
// rest code