search
HomeBackend DevelopmentPHP TutorialthinkPHP 模板中的语法学问 详细介绍(十二)

thinkPHP 模板中的语法知识 详细介绍(十二)

本章节:介绍模板中的语法,详细的语法介绍


一、导入CSS和JS文件    ==>记住常量的是大写

1、css link 、js  scr


2.import(==默认是在Public文件夹下)
//导入Public文件夹下面的Js目录中的test.js文件,import标签可以省略type属性,默认就是js的
 


//可以更改默认文件夹 设置basepath属性
//就会在 根目录下找到 Other/Js/my.js,就不是默认的Public目录

3.load
//方法可以自动检测导入的文件类型


二、分支结构
1、if

男人哭吧哭吧不是罪!

做女人挺好的!




未成年

奋斗吧少年!

成年

>  gt
== eq
>= egt
!= neq
=== heq
!== nheq


//变量不要加 $  直接名字myAge 默认会加$
太小啦你
你也太小
你还差不多
这里是默认值

三、循环结构
1.for

  /*
   start(必须):循环变量开始值
    end(必须):循环变量结束值
    name(可选):循环变量名,默认值为i
    step(可选):步进值,默认值为1,自加!
    comparison(可选):判断条件,默认为lt
  */
就是我们php for中的i



//倒序



{$j} abc
{$j} abc



2.volist(数组遍历)

{$v.username}


//从下表=1的开始取2条




//遍历多维数组

--


3.foreach

{$k}-------{$v}



四、特殊标签(手册也有详细介绍哦)
1、比较标签
eq或者 equal 等于 
模板中://等同于if else的使用  number传的变量

如果传的name=10我就输出这里也!

不等于10我就输出这里哦!

neq 或者notequal 不等于 
gt 大于 
egt 大于等于 
lt 小于 
elt 小于等于 
heq 恒等于 
nheq 不恒等于 


2.范围标签(类似if else逻辑和书写方式)
in      

在这些数字里面

不在这些数字的范围内


在这些数字里面

不在这些数字的范围内

between
//1-10之间

{$number}在1-10之间

{$number}不在1到10之间


notbetween-->标签来判断变量不在某个范围内
输出内容1


3.present
标签来判断模板变量是否已经赋值,
m有赋值m没有赋值
4.Empty
empty标签判断模板变量是否为空,
number为空赋值number有值
5.Defined 
判断常量是否已经定义
6.Define
在模板中定义常量
7.Assing
在模板中给变量赋值

五、其他标签使用
1、*在模板中直接使用PHP代码
echo "我是乐杨俊"  //注意里面只能写php的代码,嵌入tp的标签是不能用的
2、建议更改左右定界符
在配置文件中改变
'TMPL_L_DELIM'=>''TMPL_R_DELIM'=>'}>', //修改右定界符
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
What is PDO in PHP?What is PDO in PHP?Apr 28, 2025 pm 04:51 PM

The article discusses PHP Data Objects (PDO), an extension for database access in PHP. It highlights PDO's role in enhancing security through prepared statements and its benefits over MySQLi, including database abstraction and better error handling.

What is Memcache and Memcached in PHP? Is it possible to share a single instance of a Memcache between several projects of PHP?What is Memcache and Memcached in PHP? Is it possible to share a single instance of a Memcache between several projects of PHP?Apr 28, 2025 pm 04:47 PM

Memcache and Memcached are PHP caching systems that speed up web apps by reducing database load. A single instance can be shared among projects with careful key management.

What is PEAR in PHP?What is PEAR in PHP?Apr 28, 2025 pm 04:38 PM

PEAR is a PHP framework for reusable components, enhancing development with package management, coding standards, and community support.

What are the uses of PHP?What are the uses of PHP?Apr 28, 2025 pm 04:37 PM

PHP is a versatile scripting language used mainly for web development, creating dynamic pages, and can also be utilized for command-line scripting, desktop apps, and API development.

What was the old name of PHP?What was the old name of PHP?Apr 28, 2025 pm 04:36 PM

The article discusses PHP's evolution from "Personal Home Page Tools" in 1995 to "PHP: Hypertext Preprocessor" in 1998, reflecting its expanded use beyond personal websites.

How can you prevent session fixation attacks?How can you prevent session fixation attacks?Apr 28, 2025 am 12:25 AM

Effective methods to prevent session fixed attacks include: 1. Regenerate the session ID after the user logs in; 2. Use a secure session ID generation algorithm; 3. Implement the session timeout mechanism; 4. Encrypt session data using HTTPS. These measures can ensure that the application is indestructible when facing session fixed attacks.

How do you implement sessionless authentication?How do you implement sessionless authentication?Apr 28, 2025 am 12:24 AM

Implementing session-free authentication can be achieved by using JSONWebTokens (JWT), a token-based authentication system where all necessary information is stored in the token without server-side session storage. 1) Use JWT to generate and verify tokens, 2) Ensure that HTTPS is used to prevent tokens from being intercepted, 3) Securely store tokens on the client side, 4) Verify tokens on the server side to prevent tampering, 5) Implement token revocation mechanisms, such as using short-term access tokens and long-term refresh tokens.

What are some common security risks associated with PHP sessions?What are some common security risks associated with PHP sessions?Apr 28, 2025 am 12:24 AM

The security risks of PHP sessions mainly include session hijacking, session fixation, session prediction and session poisoning. 1. Session hijacking can be prevented by using HTTPS and protecting cookies. 2. Session fixation can be avoided by regenerating the session ID before the user logs in. 3. Session prediction needs to ensure the randomness and unpredictability of session IDs. 4. Session poisoning can be prevented by verifying and filtering session data.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software