


Summary of how to use ThinkPHP's built-in template engine_PHP tutorial
ThinkPHP’s built-in template engine is an independently innovative XML compilation template engine. The following uses a case to share the usage of some commonly used template tags in ThinkPHP’s built-in template engine, including variable output, looping, judgment, comparison, etc. , these are relatively basic usages and cannot include all tags and features of ThinkPHP's built-in template engine.
(1) The following is the source code of the controller IndexAction class
<?php class IndexAction extends Action{ public function index() { $_SESSION['name'] = 'ThnkPHP Session'; $vo = array('id'=>1,'name'=>'ThinkPHP','email'=>'liu21st@gmail.com'); $this->assign('vo',$vo); $obj = (object)$vo; $this->assign('obj',$obj); $this->assign('array',array(5,260,13,7,40,50,2,1)); $this->assign('num1',6); $this->assign('num2',2); $this->assign('num',6); $this->display(); } } ?>
(2) The following demonstrates some basic usage of variables, constants and arrays assigned by the above controller to the template
Universal variable output
num1:{$num1}
Object output
id:{$obj:id}
name:{$obj:name}
Array output
id:{$vo['id']}
name:{$vo['name']}
Automatically determine array and object output
id:{$vo.id}
name:{$vo.name}
System constant output (system constants do not need to be assigned in the controller)
{$Think.now|date='Y-m-d H:i:s',###}
{$Think.server.PHP_SELF}
{$Think.session.name}
Use functions for variables (this can be built-in functions or custom functions)
{$vo.name|strtolower|ucwords}
Foreach output
{$key}:{$item}
The following example uses loop tags, Switch tags, and comparison tags
[{$i}]
{$val} is greater than 15
{$val} is less than 10
The output result is similar to:
[1] Odd numbered lines 5 less than 10 length 1
[2] Even lines 260 is greater than 5 260 is greater than 15 The length is 3
[3] Odd lines 13 is greater than 5 and length is 2
[4] Even lines 7 is greater than 5, 7 is less than 10, length is 1
[5] Odd lines 40 greater than 5 40 greater than 15 length 2
[6] Even lines 50 is greater than 5 50 is greater than 15 length is 2
[7] Odd lines 2 less than 10 and length 1
[8] Even lines 1 is less than 10 and length is 1
ThinkPHP built-in template engine comparison tag
The output result is similar to:
Greater than 3
Less than 3
Conditional judgment
{$num} is greater than 5
{$num} is greater than 3
Others{$num}
The output result is similar to:
6 is greater than 5
Articles you may be interested in
- The last record to determine the volist loop in thinkphp template
- System variables commonly used in Thinkphp templates Summary
- How to set the jump waiting time for thinkphp page jump (successerror)
- Summary of query skills in ThinkPHP
- Full analysis of Thinkphp internal function ADSLCFUI shortcut method
- How to turn off caching in thinkphp
- php statistics search engine access records
- thinkphp prints the last sql statement

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools