欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

smarty3 中register_function();报错问题

shiping1 的头像

smarty3 中register_function();报错问题

  
 
<?php
include('../init.inc3.php');
$tpl->registerPlugin('function','hello','test');
function test($arg) {
extract($arg);
Return $name;
}
$tpl->display('1.tpl');
?>
用$tpl->registerPlugin来代替;
void registerPlugin(string type,
                    string name,
                    mixed callback,
                    bool cacheable,
                    mixed cache_attrs);

可以看到,该函数仅仅比register_function多了第一个参数,string type,那么该参数是做什么用的呢?文档上是这么定义的:

type defines the type of the plugin. Valid values are "function", "block", "compiler" and "modifier".

翻译过来也就是说该参数定义了插件的类型,有效值为"function","block","complier","modifier"中的一个,看到这里大家应该明白了吧,在register_function中,只能注册function这一种类型,而该函数可以注册四种类型,其余的用法和register_function基本一致。


来自 http://blog.sina.com.cn/s/blog_6794231c0100vmiv.html


普通分类: