Heim  >  Artikel  >  Backend-Entwicklung  >  Thinkphp模板中使用自定义函数的方法_PHP教程

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

WBOY
WBOYOriginal
2016-07-21 15:16:27832Durchsuche

注意:自定义函数要放在项目应用目录/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=###}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325943.htmlTechArticle注意:自定义函数要放在项目应用目录/common/common.php中。 这里是关键。 模板变量的函数调用格式:{$varname|function1|function2=arg1,arg2,### } 说...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn