<table cellspacing="0" cellpadding="0" border="0" width="100%" summary="Header navigation table"><tbody><tr><th align="center" colspan="3">Smarty - the compiling PHPtemplate engine</th> </tr><tr><td valign="bottom" align="left" width="25%"><a accesskey="P" href="api.load.filter.html">Prev</a></td> <td valign="bottom" align="center" width="50%">Chapter 13. Smarty Class Methods()</td> <td valign="bottom" align="right" width="25%"><a accesskey="N" href="api.registerplugin.html">Next</a></td> </tr></tbody></table>
# registerFilter()[注册过滤器]
Name
registerFilter() ― dynamically register filters 动态注册过滤器
Description
void registerFilter(string type, mixed callback);
Use this to dynamically register filters to operate on a templates. It uses the following parameters:
type defines the type of the filter. Valid values are "pre", "post", "output" and "variable".
callback defines the PHP callback. it can be either:
1.A string containing the function name
2.An array of the form array(&$object, $method) with &$object being a reference to an object and $method being a string containing the method-name
3.An array of the form array($class, $method) with $class being the class name and $method being a method of the class.
本函数在模板中动态地注册过滤器。其参数如下:
“type”定义过滤器的类型,其值为下列之一:“pre”、“post”、“output”和“variable”;
“callback”为定义的php回调函数,其类型为下列之一:
1、包含函数名的字符串;
2、格式为(&$object, $method)的数组,其中,&$object为引用对象,$method为包含方法名的字符串;
3、格式为($class, $method)的数组,其中,$class为类名,$method为类中的方法。
<table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 技术提示 </caption> <tr><td>Technical Note<br/> If the chosen function callback is of the form array(&$object, $method), only one instance of the same class and with the same $method can be registered. The latest registered function callback will be used in such a scenario. <br/> 如果选择array(&$object, $method)格式的回调函数,带相同方法($method)的相同类,只能注册一个实例。在这种情况下将使用最后注册的回调函数。</td> </tr></table>
译注
| 预过滤器(Prefilters)、后过滤器(Postfilters)和输出过滤器(Output Fiters)都可以使用本方法注册。 |
|-----|
A prefilter runs through the template source before it gets compiled. See template prefilters for more information on how to setup a prefiltering function.
A postfilter runs through the template code after it was compiled to PHP. See template postfilters for more information on how to setup a postfiltering function.
A outputfilter operates on a template's output before it is displayed. See template output filters for more information on how to set up an output filter function.
See also unregisterFilter(), loadFilter(), $autoload_filters, template pre filters template post filters template output filters section.
预过滤器在模板资源被编译之前运行。查看[模板预过滤器](#)获取更多关于怎么设置预过滤器函数的信息。
发送过滤器在模板被编译为php之后运行。查看[模板发送过滤器](#)获取更多关于怎么设置发送过滤器函数的信息。
输出过滤器在模板输出未显示之前运行。查看[模板输出过滤器](#)获取更多关于怎么设置输出过滤器函数的信息。
参见[unregisterFilter()](#)、[loadFilter()](#)、[$autoload_filters](#)、[模板预过滤器](#)、[模板发送过滤器](#)、[模板输出过滤器](#)章节。
<table cellspacing="0" cellpadding="0" border="0" width="100%" summary="Footer navigation table"><tbody><tr><td valign="top" align="left" width="33%"><a accesskey="P" href="api.load.filter.html">Prev</a></td> <td valign="top" align="center" width="34%"><a accesskey="H" href="index.html">Home</a></td> <td valign="top" align="right" width="33%"><a accesskey="N" href="api.registerplugin.html">Next</a></td> </tr><tr><td valign="top" align="left" width="33%">loadFilter()<br/> 加载过滤器</td> <td valign="top" align="center" width="34%"><a accesskey="U" href="api.functions.html">Up</a></td> <td valign="top" align="right" width="33%">registerPlugin()<br/> 注册插件</td> </tr></tbody></table>
- Smarty模板编译引擎
- 序
- 译序
- I.开始
- 第一章. 什么是Smarty?
- 第二章. 安装
- II.模板设计者篇
- 第三章.基本语法
- 注释
- 变量
- 函数
- 属性
- 双引号里嵌入变量
- 数学运算
- 忽略Smarty解析
- 第四章.变量
- 从PHP分配的变量
- 从配置文件读取的变量
- 变量范围
- {$smarty}保留变量
- 第五章.变量调节器
- capitalize
- cat
- count_characters
- count_paragraphs
- count_sentences
- count_words
- date_format
- default
- escape
- indent
- lower
- nl2br
- regex_replace
- replace
- spacify
- string_format
- strip
- strip_tags
- truncate
- upper
- wordwrap
- 第六章.组合修改器
- 第七章.内置函数
- {$var=}
- {append}
- {assign}
- {block}
- {call}
- {capture}
- {config_load}
- {debug}
- {extends}
- {for}
- {foreach},{foreachelse}
- @index
- {function}
- {if},{elseif},{else}
- {include}
- {include_php}
- {insert}
- {ldelim},{rdelim}
- {literal}
- {nocache}
- {php}
- {section},{sectionelse}
- .index
- {while}
- 第八章.自定义函数
- {counter}
- {cycle}
- {eval}
- {fetch}
- {html_checkboxes}
- {html_image}
- {html_options}
- {html_radios}
- {html_select_date}
- {html_select_time}
- {html_table}
- {mailto}
- {math}
- {textformat}
- 第九章.配置文件
- 第十章.调试控制台
- III.模板程序员篇
- 第十一章 常量
- SMARTY_DIR
- 第十二章 Smarty类变量
- $template_dir
- 第十三章.Smarty类方法
- append()
- appendByRef()
- assign()
- assignByRef()
- clearAllAssign()
- clearAllCache()
- clearAssign()
- clearCache()
- clearCompiledTpl()
- clearConfig()
- compileAllConfig()
- compileAllTemplates()
- configLoad()
- createData()
- createTemplate()
- disableSecurity()
- display()
- enableSecurity()
- fetch()
- getConfigVars()
- getRegisteredObject()
- getTags()
- getTemplateVars()
- isCached()
- loadFilter()
- registerFilter()
- registerPlugin()
- registerObject()
- registerResource()
- templateExists()
- unregisterFilter()
- unregisterPlugin()
- unregisterObject()
- unregisterResource()
- testInstall()
- 第十四章.缓存
- 建立缓存
- 多重缓存
- 缓存集合
- 控制插件输出的可缓存性
- 第十五章.高级特性
- 安全
- 通过模板更改设置
- 模板继承
- 数据流
- 对象
- 静态类
- 预过滤器
- 后过滤器
- 输出过滤器
- 缓存处理函数
- 资源
- 第十六章.以插件扩展Smarty
- 插件如何工作
- 命名约定
- 编写插件
- 模板函数
- 调节器
- 块函数
- 编译函数
- 预滤器/后滤器
- 输出过滤器
- 资源
- 插入
- Ⅳ.附录
- 第十七章.疑难解答
- Smarty/PHP 错误
- 第十八章.使用技巧和经验
- 空白变量处理
- 默认变量处理
- 传递变量标题给头模板
- 日期
- WAP/WML
- 组件化模板
- 拒绝电子邮件地址
- 第十九章. 相关资源
- 第二十章. 漏洞
- 3.0安装包
- 2.x版本升级至3.x版本的提示
- 3.0.x使用指南
- 翻译人员列表