LAMP架构
Smarty包
安装配置: 官网下载最新版本:http://www.smarty.net/download 解压后把libs和configs目录按如下设置拷贝出来
路径设置:templates/templates_c/cache/configs/libs/注意:templates_c和cache两个目录的权限要设置成777(chmod -R 777 templates_c cache)
Helloworld:在templates目录下增加一个demo.tpl的文件,里面写上hello worldindex.php文件如下:assign("result", $res);$smarty->display('demo.tpl');?>至此,基本的hello world程序就写好了,输入url,打开网页,就能看到了。smarty采用变量替换的方法,把php中的变量替换到.tpl模板文件中,tpl模板文件中的变量、表达式等语句使用{$data},这些变量在php中通过assign赋值代入
判断语句:{if $name eq "Fred"} Welcome Sir. {elseif $name eq "Wilma"} Welcome Ma'am. {else} Welcome, whatever you are. {/if}
循环语句:{foreach from=$data.list item=one name=f} {if $smarty.foreach.f.iteration<4} 判断循环次数 {/if}{/foreach}
其它:1)对字母作截断显示{$NAME|truncate:16:"..."}2)urlencode:{$data|escape:"url"}3)嵌套{include file="block/sideshare.tpl"}以templates为起始目录
可以使用以下条件修饰词:eq、ne、neq、gt、lt、lte、le、gte、ge、is even、is odd、is not even、is not odd、not、mod、div by、even by、odd by、==、!=、>、<、<=、>=. 使用这些修饰词时必须和变量或常量用空格格开END
templates_c和cache两个目录的权限要设置成777,否则无法打开网页
js中的{}使用时前后需要留出空格,否则会引起混淆导致失败