Home  >  Article  >  php教程  >  Thinkphp模板中使用自定义函数的方法

Thinkphp模板中使用自定义函数的方法

WBOY
WBOYOriginal
2016-06-13 11:58:131030browse

注意:自定义函数要放在项目应用目录/common/common.php中。 这里是关键。

模板变量的函数调用格式:{$varname|function1|function2=arg1,arg2,### }

说明:

{ 和 $ 符号之间不能有空格,后面参数的空格就没有问题;

###表示模板变量本身的参数位置 ;

支持多个函数,函数之间支持空格 ;

支持函数屏蔽功能,在配置文件中可以配置禁止使用的函数列表 ;

支持变量缓存功能,重复变量字串不多次解析。

使用例子:

{$webTitle|md5|strtoupper|substr=0,3}

{$number|number_format=2}

{$varname|function1|function2=arg1,arg2,### }

实例:

复制代码 代码如下:


function Cate($cid){
$Cate=D('Cate');
$Cate=$Cate->where('id='.$cid)->find();
return $Cate['title'];
}


我想在模板中调用这个函数则在模板中可以这样写

{$vo.cid|cate=###}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn