search
HomePHP FrameworkThinkPHPHow to call functions in thinkphp

How to call functions in thinkphp

thinkphp template calls the function method:

{变量|函数1|函数2|函数3=参数1,参数2,参数3,###}

is the 4th parameter, which represents the replacement of the variable with the 4th parameter

Example:

{$username|substr=0,3}取标题中前3个字符
{$times|date='Y-m-d H:i:s',###}将times时间戳转换为日期格式

Usage of colon execution function: output method and execute return value

{:U('user/insert')}

Example:

{:time()} 会输出当前日期格式 ,会被解析成 <?php echo time(); ?>

Usage of wavy line function: execution method but Do not output

{~function()}

Example:

{~substr("aaaaaaa",3)} 执行后不会输出,会背解析成 <?php substr ?>
{$Think.get.url中get过来的参数}
{$Think.server.server中的变量}
{$Think.session.session中的id|md5} 如果需要的话还可以对值MD5一下
{$Think.cookie.cookie中的id}
{$Think.config.db_host} 读取config中的配置信息
{($title)?($title):&#39;当前没有值&#39;} 当前参数若没有值,则显示后面的描述
<switch name="">
<case value="1">aaaaaa</case>
<case value="2">bbbbbbbbb</case>
<default />没有数据
</switch>
<eq name="a" value="3">a等于3<else />a不等于3</eq>
<eq name="a|strlen" value="1">a的长度等于1<else />a长度不等于1</eq>
<in name="a" value="1,2,3,4">变量a值在1,2,3,4范围内就打印</in>
<notin name="a" value="1,2,3,4">变量a值不在1,2,3,4范围内就打印</notin>

or use ###
<range name="a" value="1,2,3,4" type="in">a在1,2,3,4范围内</range> //type改为notin就是不在,该方法可替代in和notin
<empty name="a">a变量为空</empty>
<notempty name="a">a变量不为空</notempty>

The above is the detailed content of How to call functions in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use