Home  >  Article  >  Backend Development  >  .tpl与.php

.tpl与.php

WBOY
WBOYOriginal
2016-06-23 13:34:092418browse

最近在学习smarty框架
看到一些 .tpl文件里写着html和php代码
.tpl与.php有什么区别
(个人想法:  纯php代码就用.php  php+html等混合代码用.tpl)


回复讨论(解决方案)

tpl 是 template (中文释义:模板) 的缩写

smarty 是一种模板引擎,它使用自定义的模板语言,实现了显示逻辑和业务逻辑的分离(分别对应 MVC 的 V 和 M)
使用模板引擎的好处在于:在设计业务逻辑代码时,完全不需要考虑以后将如何展示运行的结果。这就有可能时程序得以精益求精
而在做用户界面时,也不需要知道数据时怎么来的,只需将数据按界面需要显示出来就可以了

无论是否使用模板引擎,最终执行的都是 php+html 混合编码

.tpl只是模版,不管文件是以什么结尾,最终运行的文件都是.php
smarty 模板引擎就是做这种分离工作的,当然还有一起其他的功能

哇,楼上的头像,让人想入非非。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn