ThinkPHP template output display
This article mainly introduces the usage of ThinkPHP template output display, and analyzes in detail the usage of ThinkPHP using display to call various template outputs in the form of examples. It is a very common practical skill. Friends who need it can refer to it
This article analyzes the usage of ThinkPHP template output display in an example. Share it with everyone for your reference. The specific analysis is as follows:
After the template variable is assigned, the template file needs to be called to output the relevant variables. The template call is implemented through the display method. We use it at the end of the operation method:
$this->display();
Output template, according to the previous template definition rules, because the system will automatically locate the template file according to the default rules, so usually the display method can output the corresponding template without any parameters. This is the simplest usage of template output.
There are always exceptions to things, or there may be no need to store them in directories by module at all, but the display method can always help you solve the problem.
The Display method provides several rules so that you can output the template you need as you like, no matter where your template file is.
Let’s look at the specific usage:
1. Call other operation templates of the current module
Format: display('operation name')
For example , Assuming that the current operation is the read operation under the User module, we need to call the edit operation template of the User module, using:
$this->display('edit');
There is no need to write the path and suffix of the template file.
2. Call the operation templates of other modules
Format: display('Module name: operation name')
For example, currently it is the User module, we need to call the Member module For the read operation template, use:
$this->display('Member:read');
This method does not require writing the path and suffix of the template file. Strictly speaking, the module name and operation name here do not necessarily need to have corresponding modules or operations. It's just a directory name and file name. For example, your project may not have a Public module at all, and there is no menu operation for the Public module, but you can still use
$this->display('Public:menu');
to output this template file. Understand this, template The output will be clear.
3. Call the operation template of other themes
Format: display('topic name: module name: operation name')
For example, we need to call Edit operation template of the User module of the Xp theme, use:
$this->display('Xp:User:edit');
This method requires specifying the module and operation name
4. Direct full path output template
Format: display ('Template file name')
For example, we directly output the menu.html template file under the current Public directory, using:
$this->display('./Public/menu.html');
This method requires specifying the template path and suffix, here The Public directory is located below the current project entry file location. If it is another suffix file, direct output is also supported, for example:
$this->display('./Public/menu.tpl');
As long as ./Public/menu.tpl is an actual existing template file, if If you use a relative path, please note that the current location is relative to the entry file of the project, not the template directory.
In fact, the display method has other parameters and usages.
Sometimes we need to output a specified encoding for a template page instead of the default encoding. You can use:
$this->display('Member:read', 'gbk');
Or the output template file is not in text/html format, but in XML Format, you can use:
$this->display('Member:read', 'utf-8', 'text/xml');
If your website output encoding is not the default encoding, you can use:
'DEFAULT_CHARSET'=> 'gbk'
If you want to output XML format, you can use:
'TMPL_CONTENT_TYPE'=> 'text/xml'
If you do not need to render the template file but directly output the content, you can use the show method, for example:
$this->show($content, 'utf-8', 'text/xml');
The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to PHP Chinese website!
Related recommendations:
Thinkphp5.0's method of automatically generating modules and directories
ThinkPHP template range judgment output In tag Usage with Range tag
The above is the detailed content of ThinkPHP template output display. For more information, please follow other related articles on the PHP Chinese website!

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

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

Fujifilm fans were recently very excited at the prospect of the X-T50, since it presented a relaunch of the budget-oriented Fujifilm X-T30 II that had become quite popular in the sub-$1,000 APS-C category. Unfortunately, as the Fujifilm X-T50's launc

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

We frequently report on devices based on displays with electronic ink, such as e-readers. The technology offers a number of advantages: it can be read in bright environments without a backlight, and it only requires power when switching without light
