search
HomeBackend DevelopmentPHP Tutorial PHP有无必要运用Smarty呢?

PHP有无必要使用Smarty呢??

使用Smarty是可以处理很多东西,但是近来本人相当的困惑,有无这个必要呢????它提供了很多页面的模板指令,但是我在开发的过程中实际上都很少用到... 每次都挂上这个东西是不是浪费呢??

?

比如这个生成RSS的代码,使用原生的PHP相当的简单

<?php
header("Content-Type:text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>' //这后面不能加换行符;
?>
<rss version="2.0">
	<channel>
		<title>Module Action Menu</title>
		<link>appstore/contenter/action-menu/exep-menu.xml</link>
		<description>
			每个菜单模块下有多个菜单链接,每个连接对应此文件中的一个item项.
		这个文件必须放在外部访问不到的地方,客户端使用一个统一的控制器来获取相应的这个文件.
		此文件由PHP程序动态生成,并使用unicode编码,客户端获取后,反解析显示.
			为了提高效率,在后期可以生成缓存文件.
			
		</description>
		<language>zh-cn</language>
		<copyright>
			Copyright ? 2006 Beijing Extreme Club. All Rights Reserved
		</copyright>
		
		<pubDate></pubDate>
		<lastBuildDate></lastBuildDate>
		<docs>http://www.beijingextreme.com.cn/rss</docs>
		<generator>iamsese vb2005xu</generator>
		<managingEditor>vb2005xu</managingEditor>
		<webMaster>trcn17@gmail.com</webMaster>
		
<?php
$menu_text  = array() ;
$menu_text['zh'] = array(
	'地理资讯','历史资讯','宗教',
	'传说','气候','高原反应',
	'西藏推荐行程','西藏寺庙','名山险峰',
	'地图','相册'
) ;
$menu_text['ru'] = array(
	'Географическая справка','Историческая справка','Религия',
	'Мифы','Климат','Горная болезнь',
	'Рекомендуемые маршруты в Тибете','Монастыри Тибета','Достопримечательности',
	'Карты','Фотогалерея'
) ;

$forwardCtl_Tibet = "f.php?action=" ;
$forwardCtl_Tibet = str_ireplace('&','#p#',$forwardCtl_Tibet);
$menu_href = array(
	"{$forwardCtl_Tibet}dl","{$forwardCtl_Tibet}lsh","{$forwardCtl_Tibet}zj",
	"{$forwardCtl_Tibet}chsh","{$forwardCtl_Tibet}qh","{$forwardCtl_Tibet}gyfy",
	"{$forwardCtl_Tibet}tjlch","{$forwardCtl_Tibet}xzsm","{$forwardCtl_Tibet}mshxf",
	"{$forwardCtl_Tibet}dt","{$forwardCtl_Tibet}xc"
) ;

for ($i=0;$i<count($menu_text['ru']);$i++){
?>
		<item>
			<title><?php echo $menu_text['ru'][$i] ?></title>
			<link><?php echo $menu_href[$i] ?></link>
			<description>这里要注意的是注意url参数连接字符的置换,这里使用#p#来代替</description>
			<pubDate><?php echo date('Y-m-d H:i:s') ?></pubDate>
			<guid><?php echo $i+1 ?></guid>
			<t><?php echo $menu_text['zh'][$i] ?></t>
		</item>
<?php	
}
?>		
		
	</channel>
</rss>

?

1 楼 巫山霏云 2009-04-08  
如果是我的话,我会考虑按照需求和扩展性来....
像RSS这种东西我是觉得直接用php也挺好的

2 楼 zwws 2009-04-08  
就是看情况...个人开发的话简单点挺好的.

3 楼 ycmhn 2009-04-08  
smarty主要是把样式展现和逻辑分开的
当然用php也可以做到
用php做需要精心设计文件组织,用smarty可以简化不少
何况smarty还可以很方便的静态化页面,也算是一个不错的功能
不过一般如果很小的项目似乎也不能从smarty得到多大的好处

4 楼 syu 2009-04-08  
这么多年一直不是很喜欢smarty类的模板引擎.
就我的感受而言,smarty存在的目的就是为了将VC分离,其本身自带的那么多控制流程走向的东西,大概本意仅是用在实在得用的时候做为补充方法.一但在模板中用太多控制条件,那跟直接嵌入PHP也就没什么区别了.两相比较我更喜欢再轻型一点的smarttemplate.

5 楼 zwws 2009-04-09  
syu 写道
这么多年一直不是很喜欢smarty类的模板引擎.
就我的感受而言,smarty存在的目的就是为了将VC分离,其本身自带的那么多控制流程走向的东西,大概本意仅是用在实在得用的时候做为补充方法.一但在模板中用太多控制条件,那跟直接嵌入PHP也就没什么区别了.两相比较我更喜欢再轻型一点的smarttemplate.
恩,基本上感觉是和你一样的,判断条件多的时候,if else不胜其烦。

轻量级的就够了。

6 楼 imjl 2009-04-10  
喜欢smarty的

如果你只知道代替,那我想strtr也许更方便

7 楼 only_java 2009-04-10  
zwws 写道
syu 写道
这么多年一直不是很喜欢smarty类的模板引擎.
就我的感受而言,smarty存在的目的就是为了将VC分离,其本身自带的那么多控制流程走向的东西,大概本意仅是用在实在得用的时候做为补充方法.一但在模板中用太多控制条件,那跟直接嵌入PHP也就没什么区别了.两相比较我更喜欢再轻型一点的smarttemplate.
恩,基本上感觉是和你一样的,判断条件多的时候,if else不胜其烦。

轻量级的就够了。
不是吧?smarty还有缓存的功能啊!

8 楼 skyfox 2009-05-01  
only_java 写道
zwws 写道
syu 写道
这么多年一直不是很喜欢smarty类的模板引擎.
就我的感受而言,smarty存在的目的就是为了将VC分离,其本身自带的那么多控制流程走向的东西,大概本意仅是用在实在得用的时候做为补充方法.一但在模板中用太多控制条件,那跟直接嵌入PHP也就没什么区别了.两相比较我更喜欢再轻型一点的smarttemplate.
恩,基本上感觉是和你一样的,判断条件多的时候,if else不胜其烦。

轻量级的就够了。
不是吧?smarty还有缓存的功能啊!
有缓存功能的多了,又不止只有smarty.

9 楼 七月十五 2009-05-03  
这个问题争论不休,公说公理,婆说婆理
发几个争论帖子观摩一下吧
http://bbs.phpchina.com/viewthread.php?tid=110467
http://bbs.phpchina.com/viewthread.php?tid=67407
http://bbs.phpchina.com/viewthread.php?tid=67221
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
Dependency Injection in PHP: Avoiding Common PitfallsDependency Injection in PHP: Avoiding Common PitfallsMay 16, 2025 am 12:17 AM

DependencyInjection(DI)inPHPenhancescodeflexibilityandtestabilitybydecouplingdependencycreationfromusage.ToimplementDIeffectively:1)UseDIcontainersjudiciouslytoavoidover-engineering.2)Avoidconstructoroverloadbylimitingdependenciestothreeorfour.3)Adhe

How to Speed Up Your PHP Website: Performance TuningHow to Speed Up Your PHP Website: Performance TuningMay 16, 2025 am 12:12 AM

ToimproveyourPHPwebsite'sperformance,usethesestrategies:1)ImplementopcodecachingwithOPcachetospeedupscriptinterpretation.2)Optimizedatabasequeriesbyselectingonlynecessaryfields.3)UsecachingsystemslikeRedisorMemcachedtoreducedatabaseload.4)Applyasynch

Sending Mass Emails with PHP: Is it Possible?Sending Mass Emails with PHP: Is it Possible?May 16, 2025 am 12:10 AM

Yes,itispossibletosendmassemailswithPHP.1)UselibrarieslikePHPMailerorSwiftMailerforefficientemailsending.2)Implementdelaysbetweenemailstoavoidspamflags.3)Personalizeemailsusingdynamiccontenttoimproveengagement.4)UsequeuesystemslikeRabbitMQorRedisforb

What is the purpose of Dependency Injection in PHP?What is the purpose of Dependency Injection in PHP?May 16, 2025 am 12:10 AM

DependencyInjection(DI)inPHPisadesignpatternthatachievesInversionofControl(IoC)byallowingdependenciestobeinjectedintoclasses,enhancingmodularity,testability,andflexibility.DIdecouplesclassesfromspecificimplementations,makingcodemoremanageableandadapt

How to send an email using PHP?How to send an email using PHP?May 16, 2025 am 12:03 AM

The best ways to send emails using PHP include: 1. Use PHP's mail() function to basic sending; 2. Use PHPMailer library to send more complex HTML mail; 3. Use transactional mail services such as SendGrid to improve reliability and analysis capabilities. With these methods, you can ensure that emails not only reach the inbox, but also attract recipients.

How to calculate the total number of elements in a PHP multidimensional array?How to calculate the total number of elements in a PHP multidimensional array?May 15, 2025 pm 09:00 PM

Calculating the total number of elements in a PHP multidimensional array can be done using recursive or iterative methods. 1. The recursive method counts by traversing the array and recursively processing nested arrays. 2. The iterative method uses the stack to simulate recursion to avoid depth problems. 3. The array_walk_recursive function can also be implemented, but it requires manual counting.

What are the characteristics of do-while loops in PHP?What are the characteristics of do-while loops in PHP?May 15, 2025 pm 08:57 PM

In PHP, the characteristic of a do-while loop is to ensure that the loop body is executed at least once, and then decide whether to continue the loop based on the conditions. 1) It executes the loop body before conditional checking, suitable for scenarios where operations need to be performed at least once, such as user input verification and menu systems. 2) However, the syntax of the do-while loop can cause confusion among newbies and may add unnecessary performance overhead.

How to hash strings in PHP?How to hash strings in PHP?May 15, 2025 pm 08:54 PM

Efficient hashing strings in PHP can use the following methods: 1. Use the md5 function for fast hashing, but is not suitable for password storage. 2. Use the sha256 function to improve security. 3. Use the password_hash function to process passwords to provide the highest security and convenience.

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 Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!