php register_function smarty,register_function

短命女 2022-11-17 11:27 296阅读 0赞

register_function

注册函数

void register_function(string

name, mixed impl, bool cacheable, array or null cache_attrs)

Use this to dynamically register template function plugins. Pass in

the template function name, followed by the PHP function name that

implements it.

动态注册模板函数插件,前两个参数是模板函数名称和执行函数名称。

The php-function callback impl

can be either (a) a string containing the function name or (b) an array

of the form array(&$object, $method) with

&$object being a reference to an object

and $method being a string containing the

mehod-name or (c) an array of the form array(&$class,

$method) with $class being a classname

and $method being a class method of that

class.

执行函数的格式可以是一个包含函数名称的字符串;也可以是一个array(&$object,

$method)数组形式,其中&$object是一个对象的引用,而$method是它的一个方法;还可以是一个array(&$

class, $method)数组形式,其中$class是一个类的名称,$method是类中的一个方法。

$cacheable and $cache_attrs can be omitted in most

cases. See Controlling Cacheability

of Plugins’ Output on how to use them properly.

$cacheable 和 $cache_attrs

参数在大多数情况下可以省略。它们的使用方法可以查看控

制插件输出的缓存。

Example 13-22. register_function

例子 13-22. 注册函数

$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”}的格式进行格式化

发表评论

表情:
评论列表 (有 0 条评论,296人围观)

还没有评论,来说两句吧...

相关阅读

    相关 close.php,close.php

    /\\ \ alipay.trade.close(统一收单交易关闭接口) \ \ 用于交易创建后,用户在一定时间内未进行支付,可调用该接口直接将未付款的交易进行关闭。