<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-&gt;display('c:/path/to/index.tpl');<br/> 资源的名称至少由两个字符组成。只有一个字符的资源名称会被忽略,并被视为文件路径的一部分,比如$smarty-&gt;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">&lt;?php$smarty-&gt;register-&gt;resource('db', array( 'db_get_template', 'db_get_timestamp', 'db_get_secure', 'db_get_trusted') );?&gt;</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>