l assign :为模板分配变量
l assignbyref :为模板分配变量 (按引用传递)
l append :追加模板变量到一个数组中
l appendbyref :追加模板变量到一个数组中 (按引用传递)
l clearallassign
清除所有已赋值变量
l clearcache
清除缓存
l configload 加载配置文件
在smarty中,加载配置文件两种方法:
1)在模板中 {config_load file=’….’}
2)在程序中 $smarty->configload($file[,$section])
l clearconfig
清除所有配置文件变量
l display
读取、替换、输出
l fetch
读取、替换、返回
l templateexists :判断模板是否存在
尝试加载一个不存在的模板会报错,在显示之前应该判断
assign和assignbyref的区别:
display和fetch的区别:
四、 过滤器
过滤器就是用于过滤数据
1、过滤器的种类:
1)预过滤器 prefilters
2)后过滤器 postfilters
3)输出过滤器 output filters
根据触发时间的不同,划分出以上三种过滤器
2、工作流程
tpl源文件 =〉prefilter =〉编译tpl文件 => postfilter =>保存到磁盘=> 编译过的php文件执行=〉output filters(=〉如果有smarty cache的话,output filters的内容会缓存) =>结果输出。
3、注册过滤器
在smarty中,过滤器在使用之前必须注册
在2.6中,注册过滤器
l prefilters
$smarty->register_prefilter(“func”);
l postfilters
$smarty->register_postfilter(“func”);
l output filters
$smarty->register_outputfilter(“func”);
注册不同的过滤器调用不同的方法。
3.0中,注册过滤器
$smarty->registerfilter($type, $callback);
$type:过滤器类型
取值范围:
pre:预过滤器
post:后过滤器
output :输出过滤器
$callback:过滤器函数
4、代码:
预过滤和后过滤器第一次编译时会执行,或者模板发生改变后会再次执行
输出过滤器每次都会执行
以上就介绍了php—smarty-7(24),包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
