<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.register.object.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.template.exists.html">Next</a></td> </tr></tbody></table>
# registerResource()[注册资源]
Name
registerResource() ― dynamically register resources 动态注册资源
Description
void registerResource(string name,array resource_funcs);
Use this to dynamically register a resource plugin with Smarty. Pass in the name of the resource and the array of PHP functions implementing it. See template resources for more information on how to setup a function for fetching templates.
本函数动态注册一个Smarty资源插件,必须传递两个参数:资源的名称和php函数数组。关于如何建立一个函数获取模板请看[模板资源](#)部分。
<table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Technical Note<br/> A resource name must be at least two characters in length. One character resource names will be ignored and used as part of the file path, such as $smarty->display('c:/path/to/index.tpl');<br/> 资源的名称至少由两个字符组成。只有一个字符的资源名称会被忽略,并被视为文件路径的一部分,比如$smarty->display('c:/path/to/index.tpl');。</td> </tr></table>
The php-function-array resource_funcs must have 4 or 5 elements.
With 4 elements the elements are the functions-callbacks for the respective source, timestamp,secure and trusted functions of the resource.
With 5 elements the first element has to be an object reference or a class name of the object or class implementing the resource and the 4 following elements have to be the method names implementing source, timestamp, secure and trusted.
第二个参数“resource_funcs”必须包含4或5个元素。
包含4个元素的情况为回调函数元素,分别处理资源的“source 资源”、“timestamp 时间戳”、“secure 安全”、“trusted 可信的”的函数。
5个元素的情况为:第一个元素必须是一个对象的引用,或者是对象所在的类名,或者是执行资源的类。后面的4个元素是实现处理“source 源文本”、“timestamp 时间戳”、“secure 安全”、“trusted 可信的”的方法名。
<table class="EXAMPLE" cellspacing="0" cellpadding="0" border="0" width="100%"><tbody><tr><td> <div class="EXAMPLE"><a name="AEN31330" id="AEN31330"/> <b><span class="PROGRAMLISTING">Example 13.30. registerResource()</span><br/></b><table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td> <pre class="PROGRAMLISTING"><?php$smarty->register->resource('db', array( 'db_get_template', 'db_get_timestamp', 'db_get_secure', 'db_get_trusted') );?></pre> </td> </tr></tbody></table><p> 参见<a href="api.unregister.resource.html">unregisterResource()</a>和模板<a href="template.resources.html">资源</a>章节。</p> </div> </td> </tr></tbody></table>
<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.register.object.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.template.exists.html">Next</a></td> </tr><tr><td valign="top" align="left" width="33%">registerObject()<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%">templateExists()<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使用指南
- 翻译人员列表