How to use custom functions in Thinkphp templates_PHP tutorial

WBOY
Release: 2016-07-21 15:16:27
Original
879 people have browsed it

Note: Custom functions should be placed in the project application directory/common/common.php. Here's the key.

Function calling format of template variables: {$varname|function1|function2=arg1, arg2, ### }

Note: There cannot be between

{ and the $ symbol If there are spaces, there will be no problem with spaces in subsequent parameters;

### indicates the parameter position of the template variable itself;

supports multiple functions, and spaces are supported between functions;

Supports function shielding function, and a list of prohibited functions can be configured in the configuration file;

Supports variable caching function, and repeated variable strings will not be parsed multiple times.

Usage example:

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

{$number|number_format=2}

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

Example:

Copy code The code is as follows:

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

If I want to call this function in the template, I can write this in the template

{ $vo.cid|cate=###}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325943.htmlTechArticleNote: Custom functions should be placed in the project application directory/common/common.php. Here's the key. The function call format of template variables: {$varname|function1|function2=arg1, arg2, ### } says...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template