PHP 的 ASP.NET MasterPage 相当于什么?
我是 PHP 新手。如何创建一个基础(如 asp.net 母版页)并让所有其他页面从该基础页面继承或指定我希望页面从某个基础页面继承,这样我就不必重新创建诸如标题之类的内容,导航、页脚等...
这只是更多还是 ASP.NET 母版页似乎会减慢速度并增加不必要的混乱?
I am new to PHP. How can I create a base (like an asp.net masterpage) and have all other pages inherit from the base page or designate that I want pages to inherit from a certain base page, so I don't have to recreate things like headers, navigation, footers, etc...
Is it just more or do ASP.NET Masterpages seem to slow things down and add unnecessary clutter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
php中没有这样的东西;但是,您可以使用两个函数来模拟它。
include()
和require().
就像这个
top.php
Other.php
随机文本
除了如何处理故障之外,这两个构造在各方面都是相同的。 include() 会产生警告,而 require() 会产生致命错误。
There is no such thing in php; however, there are 2 functions you can use to simulate that.
include()
andrequire().
Like this
top.php
Other.php
random text
The two constructs are identical in every way except how they handle failure. include() produces a Warning while require() results in a Fatal Error.
PHP 没有母版页。
不过,您可以为它们创建功能。
它不完全是一个主模板,
下面是一个简单的例子:
header.php
index.php
footer.php
Php doesn't have masterpages.
You can however create functionality for them.
Its not exactly a master template tho
Here is a simple example:
header.php
index.php
footer.php
我建议您使用支持继承等功能的模板引擎。使用纯 PHP 做模板是一个 PITA。
Twig 看起来很漂亮并且支持模板继承: http://www.twig-project.org/
I'd suggest you to use a template engine which supports features like inheritance. Using plain PHP for templates is a PITA.
Twig looks pretty nice and supports template inheritance: http://www.twig-project.org/
我不知道母版页应该是什么 - 但通常您从单个index.php开始,其中包括所有必要的库、文件和模板,用于格式化输出。要请求单个页面,通常您在该 index.php 上使用请求参数。
I don't know, what a masterpage should be - but normally your start with a single index.php, which includes all necessary libraries, files and also templates, which are used to format the output. To request a single page, normally you use a request-parameter on that index.php.
使用函数有一种非常好的方法:
查看示例
There is a VERY nice way using functions:
See an example