ThinkPHP template output display usage analysis, thinkphpdisplay_PHP tutorial

WBOY
Release: 2016-07-13 10:12:59
Original
797 people have browsed it

ThinkPHP template output display usage analysis, thinkphpdisplay

This article analyzes the usage of ThinkPHP template output display through examples. Share it with everyone for your reference. The specific analysis is as follows:

After assigning values ​​to template variables, you need to call the template file to output the relevant variables. The template call is implemented through the display method. We use it at the end of the operation method:

Copy code The code is as follows:
$this->display();

can output the 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 the current operation is the read operation under the User module, we need to call the edit operation template of the User module, use:

Copy code The code is as follows:
$this->display('edit');

No need to write the path and suffix of the template file.

2. Call operation templates of other modules

Format: display('module name: operation name')

For example, currently it is the User module, we need to call the read operation template of the Member module, use:

Copy code The code is as follows:
$this->display('Member:read');

This method also 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, but are just a directory name and file name. For example, Your project may not have a Public module at all, let alone the menu operation of the Public module, but you can still use it

Copy code The code is as follows:
$this->display('Public:menu');

Output this template file. Once you understand this, the template output will be clear.

3. Call operation templates of other themes

Format: display('theme name: module name: operation name')

For example, if we need to call the edit operation template of the User module of the Xp theme, use:

Copy code The code is as follows:
$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, if we directly output the menu.html template file under the current Public directory, use:

Copy code The code is as follows:
$this->display('./Public/menu.html');

This method requires specifying the template path and suffix. The Public directory here is located below the current project entry file location. If it is another suffix file, direct output is also supported, for example:

Copy code The code is as follows:
$this->display('./Public/menu.tpl');

As long as ./Public/menu.tpl is an actual template file, if a relative path is used, 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 usage.

Sometimes we need to output a specified encoding for a template page instead of the default encoding. You can use:

Copy code The code is as follows:
$this->display('Member:read', 'gbk');

Or the output template file is not in text/html format, but in XML format. You can use:

Copy code The code is as follows:
$this->display('Member:read', 'utf-8', 'text/xml' );

If your website output encoding is not the default encoding, you can use:

Copy code The code is as follows:
'DEFAULT_CHARSET'=> 'gbk'

If you want to output XML format, you can use:

Copy code The code is as follows:
'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:

Copy code The code is as follows:
$this->show($content, 'utf-8', 'text/xml');

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/917683.htmlTechArticleAnalysis of ThinkPHP template output display usage, thinkphpdisplay This article analyzes the ThinkPHP template output display usage with examples. Share it with everyone for your reference. The specific analysis is as follows: Template variables...
Related labels:
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