register_resource
注册资源

void register_resource(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.

动态注册一个资源插件,前两个参数是资源的名称和执行函数的数组。关于如何建立一个函数取出模板,请看模板资源部分。

Technical Note: 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');

注意:资源的名称主要要有两个字符组成。一个字符的资源名 称将被忽略,并被视为是文件路径的一部分,比如$smarty->display('c:/path/to/index.tpl');。

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".

执行函数数组必须包含4或5个元素。包含4个元素的情况下,这些函数分别是处理“source 源文本”、“timestamp 时间戳”、“secure 安全”、“trusted 可信的”的函数。5个元素的情况下,第一个元素必须是一个对象的引用,或者是一个类名,后面的4个元素是实现处理“source 源文本”、“timestamp 时间戳”、“secure 安全”、“trusted 可信的”的方法。

Example 13-24. register_resource
例子 13-24. 注册资源

$smarty->register_resource("db", array("db_get_template",
"db_get_timestamp",
"db_get_secure",
"db_get_trusted"));