Smarty核心内容:自定义函数及方法
来源:互联网 发布:php开源论坛 wap 编辑:程序博客网 时间:2024/05/19 10:41
自定义函数
assign 变量赋值
counter 计数器
cycle toggle交替显示
debug 控制台
eval eval 按处理模板的方式计算取得变量的值
fetch 用于从本地文件系统、HTTP或FTP上取得文件并显示文件的内容
html_checkboxes 根据给定的数据创建复选按钮组
html_image 根据给定的数据创建复选按钮组
html_options 根据给定的数据创建选项组
html_radios 根据给定的数据创建单选按钮组
html_select_date 用于创建日期下拉菜单
html_select_time 用于创建时间下拉菜单
html_table 自定义函数 html_table 将数组中的数据填充到 HTML 表格中
math math 允许模板设计者在模板中进行数学表达式运算
mailto mailto 自动生成电子邮件链接
popup_init 函数整合了 overLib(用于弹出窗口的函数库) 库
popup 用于创建javascript弹出窗口.
textformat 用于格式化文本
smarty 方法
append [添加]
append_by_ref [引用添加]
assign [赋值]
assign_by_ref [引用赋值]
clear_all_assign [清除所有赋值]
clear_all_cache [清除所有缓存]
clear_assign [清除赋值]
clear_cache [清除缓存]
clear_compiled_tpl [清除已编译模板]
clear_config [清除配置]
config_load [加载配置]
display [显示]
fetch [取得输出的内容]
get_config_vars [取配置变量的值]
// get loaded config template var 'foo'
// 得到已加载配置变量“foo”的值
$foo = $smarty->get_config_vars('foo');
// get all loaded config template vars
// 得到所有已加载配置变量的值
$config_vars = $smarty->get_config_vars();
// take a look at them
// 输出
print_r($config_vars);
get_registered_object [取得已注册的对象]
get_template_vars [取得模板变量的值]
is_cached [是否已被缓存]
load_filter [加载过滤器]
register_block [注册一个块]
用来动态注册/定义块函数插件。前两个参数指定块函数名称和执行函数的名称。
执行函数的格式可以是一个包含函数名称的字符串;也可以是一个array(&$object, $method)数组形式,其中&$object是一个对象的引用,而$method是它的一个方法;还可以是一个array(&$ class, $method)数组形式,其中$class是一个类的名称,$method是类中的一个方法。$cacheable 和 $cache_attrs 参数在大多数情况下可以省略。它们的使用方法可以查看控制插件输出的缓存。
/* PHP */
$smarty->register_block("translate", "do_translation");function do_translation ($params, $content, &$smarty, &$repeat) { if (isset($content)) { $lang = $params['lang']; // do some translation with $content return $translation; }}
{* template *}
{translate lang="br"}
Hello, world!
{/translate}
register_compiler_function [注册编译函数]
register_function [注册函数]
$smarty->register_function("date_now", "print_current_date");function print_current_date ($params) { extract($params); if(empty($format)) $format="%b %e, %Y"; return strftime($format,time());}
// now you can use this in Smarty to print the current date: {date_now}// or, {date_now format="%Y/%m/%d"} to format it.
// 现在你可以在模板中这样显示日期:{date_now}// 或者用{date_now format="%Y/%m/%d"}的格式进行格式化
register_modifier [注册修饰器]
// let's map PHP's stripslashes function to a Smarty modifier.
// 把PHP的stripslashes函数影像为Smarty模板的修饰器
$smarty->register_modifier("sslash","stripslashes");
// now you can use {$var|sslash} to strip slashes from variables
// 现在可以在模板中使用{$var|sslash}的格式来去除变量中的特殊符号了
// 如果有多种参数可以使用{$var|sslash:"1":"..."}
register_object [注册对象]
<?php// the objectclass My_Object() { function meth1($params, &$smarty_obj) { return "this is my meth1"; }}$myobj = new My_Object;// registering the object (will be by reference)$smarty->register_object("foobar",$myobj);// if we want to restrict access to certain methods or properties, list them$smarty->register_object("foobar",$myobj,array('meth1','meth2','prop1'));// if you want to use the traditional object parameter format, pass a boolean of false$smarty->register_object("foobar",$myobj,null,false);// We can also assign objects. Assign by ref when possible.$smarty->assign_by_ref("myobj", $myobj);$smarty->display("index.tpl");?>
TEMPLATE:
{* access our registered object *}
{foobar->meth1 p1="foo" p2=$bar}
{* you can also assign the output *}
{foobar->meth1 p1="foo" p2=$bar assign="output"}
the output was {$output)
{* access our assigned object *}
{$myobj->meth1("foo",$bar)}
register_outputfilter [注册输出过滤器]
register_postfilter [注册提交过滤器]
register_prefilter [注册预过滤器]
register_resource [注册资源]
trigger_error [触发错误]
template_exists [模板是否存在]
unregister_block [注销一个块]
unregister_compiler_function [注销编译函数]
unregister_function [注销函数]
unregister_modifier [注销修饰器]
unregister_object [注销对象]
unregister_outputfilter [注销输出过滤器]
unregister_postfilter [注销提交过滤器]
unregister_prefilter [注销预过滤器]
unregister_resource [注销资源]
- Smarty核心内容:自定义函数及方法
- Smarty核心内容:内建函数
- 【smarty】smarty自定义函数
- Smarty中自定义函数与调用方法
- Smarty核心内容:保留变量
- Smarty核心内容:变量调节器
- Smarty核心内容:Caching [缓存]
- 了解smarty自定义函数
- smarty自定义函数
- smarty自定义函数总结
- smarty自定义函数
- smarty自定义函数
- smarty自定义函数
- smarty自定义函数1
- smarty自定义函数
- smarty中自定义函数
- smarty自定义函数
- smarty的自定义函数
- asp.net 中数据的批量插入和更新
- Step by step Configuration FBA on SharePoint 2010 for Windows Server 2008 R2
- 求一个数组中的最大子段和
- 引用
- 你不知道的事---------printf输出指定长度字符串
- Smarty核心内容:自定义函数及方法
- Smarty核心内容:Caching [缓存]
- 不规则三角网(TIN)
- tcp udp 的echo脚本
- php标准注释
- VBA中MsgBox的几个用法
- Thoughts at one day
- Android最佳实践之:StrictMode介绍
- PHP 类与对象