search
HomeBackend DevelopmentPHP Tutorial模板引擎 - ThinkPHP中的模板标签具体有什么作用呢?

TP里有很多内置标签,判断比较、循环等等,使用PHP做服务端开发平时与前端配合较多,个人觉得这些标签会复杂化HTML的可阅读性,而且前后端工程师不应该在这些标签上浪费时间……

我想了两点:

  1. 要说继承的话,以前的项目里用CI重写过load对象,也是用PHP来进行组装HTML的。这方面也不会有很难搞的地方。

  2. 要是说前后端分离的话,我觉得web开发本身就是一个需要相关知识比较宽泛的工作,而且肯定要有对接的部分,使用了模板引擎之后前端仍然是还要写很多模板变量(少敲几个字符这倒是真的……)。

最后还是觉得,程序应该是考虑解决问题,并且考虑性能优先的。所以不是很理解模板这个设计的初衷,TP的源码没完整看,不太了解这些内置标签在性能上的问题。


刚开始用TP,也许我有理解不对的不要鄙视我……

回复内容:

TP里有很多内置标签,判断比较、循环等等,使用PHP做服务端开发平时与前端配合较多,个人觉得这些标签会复杂化HTML的可阅读性,而且前后端工程师不应该在这些标签上浪费时间……

我想了两点:

  1. 要说继承的话,以前的项目里用CI重写过load对象,也是用PHP来进行组装HTML的。这方面也不会有很难搞的地方。

  2. 要是说前后端分离的话,我觉得web开发本身就是一个需要相关知识比较宽泛的工作,而且肯定要有对接的部分,使用了模板引擎之后前端仍然是还要写很多模板变量(少敲几个字符这倒是真的……)。

最后还是觉得,程序应该是考虑解决问题,并且考虑性能优先的。所以不是很理解模板这个设计的初衷,TP的源码没完整看,不太了解这些内置标签在性能上的问题。


刚开始用TP,也许我有理解不对的不要鄙视我……

用原生PHP代码,和用模板,最后的效果是一样的,模板也会解析成原生的代码。要说效率,感觉区别不大。

我觉得你既然使用框架了,那当然还是使用他们的模板去编写代码比较好,毕竟每个模板的开发人员,都是经过深思熟虑才做了各种便利的设置。你要非得写原生PHP,那你何必用框架,而且如果不按框架的规范开发,对你以后更快捷的使用该框架也是无利的。

框架是便于我们更快速的去开发,但在使用框架的同时,对基本原理,也需要自己深层次的学习,基础还是要扎实。

我感觉模板标签的作用就是在html里少写php
php是种很灵活的语言,没有模板引擎的约束,我感觉前端html里的代码会嵌入php的方式非常多,甚至可能有些人函数还定义在里面,或者一些逻辑还写在里面,但用了模板引擎这样做的人就很少,无论是不是新手
性能什么的不需要太注重,即使使用了模板引擎,也可以将他解析成html混合php的形式将其缓存起来的,理论上你只是第一次通过正则解析完后,第二次就可以不用再次解析了.

就是为了前后端分离, 模板引擎大同小异, 前端开发人员学习它的用法的成本远远低于学习一门语言的成本.

为了编辑器的语法着色正常

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
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download

Atom editor mac version download

The most popular open source editor