当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP教程:简单认识smarty3

PHP
PHP学习中遇到的问题,请高手帮忙 - PHPchina
如何获取IIS虚拟目录的绝对路径 - PHPchina
常常说的SQL注入是怎么做的? - PHPchina
怎么对网站的Alexa排名的数据的采集? - PHPchina
遇到一个session丢失的问题。打开含有mediaplayer播放器的页面,会导致session丢失 -
做小偷遇到一个基础问题.请指教 - PHPchina
php5如何连接ACCESS 2003 - PHPchina
帮找下错误 - PHPchina
split 函数的一个问题 - PHPchina
一个全站系统的数据库设计问题,望大家都来帮帮忙 - PHPchina
分享我的PHP配置心得包含MYSQL5乱码解决 - PHPchina
深入浅出分析Linux设备驱动程序中断 (1)(3)
深入浅出分析Linux设备驱动程序中断 (1)(2)
深入浅出分析Linux设备驱动程序中断 (1)
OpenSSH可实现一次性自动管理多台服务器
如何利用程序循环来控制Perl脚本流程
PHP5应用笔记之Cookie实用攻略(上)
从失败中涉取经验 网站设计的十种常见错误
连载1:利用PHP创建由Oracle 驱动的SOAP服务
连载2:利用PHP创建由Oracle 驱动的SOAP服务

PHP教程:简单认识smarty3


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 56 ::
收藏到网摘: n/a

这些天看到了smarty 3 alpha冒头了,于是花时间做了个走访调查。下面的文字基本上来自其readme:

基本文件文件结构

index.php
/libs/ Smarty.class.php	#主文件
/libs/sysplugins/	#内部plugin internal.*
/plugins/	#外部plugin,可自由扩充 function.mailto.php modifier.escape.php
/templates/	#模板,可以是纯php或传统的smarty模板 index.tpl index_view.php

一个经典的smarty调用

PHP:
  1. require('Smarty.class.php');
  2. $smarty = new Smarty;
  3. $smarty->assign('foo','bar');
  4. $smarty->display('index.tpl');

 

和之前的版本似乎没什么差别

SINGLETON

这个有意义吗?

PHP:
  1. $smarty = Smarty::instance();

 

模板

之前的smarty模板,相当于重新定义了一套标签语言,那么smarty3提供了一种新的模板形式,直接支持php语法的模板。

但是问题就出来了,我们还有必要用模板吗?

引用php类型模板的一个例子:

PHP:
  1. $smarty->display('php:mytemplate.tpl');

 

模板中可以直接使用熟悉的语法: <?=$foo?> <?=$bar?>

使用php类型模板的话,安全问题需要自己解决。但这个对成熟的团队来说不是问题。

除此之外,新支持字符串类型的模板,感觉比较生猛,离模板之路也是渐行渐远:

PHP:
  1. $smarty->display('string:This is my template, {$foo}!');

 

smarty3的相关链接

  • Smarty 3 Alpha with SVN -- 选择googlecode提供的svn服务还是蛮省钱的
  • smarty 3开发者邮件组