thinkphp Template Output Display usage analysis, Thinkphpdisplay
This paper analyzes the thinkphp template output display usage. Share to everyone for your reference. The specific analysis is as follows:
After assigning the template variable, it is necessary to invoke the template file to output the relevant variables, and the template invocation is implemented by the display method, which we use at the end of the operation method:
Copy the Code code as follows: $this->display ();
You can export the template, define the rule according to the previous template, because the system will automatically locate the template file according to the default rules, so the display method usually outputs the corresponding template without any parameters, which is the simplest use of the template output.
There's always an exception to this, or there's no need to sub-catalog it by module, but the display method can always help you solve the problem.
The display method provides several rules that allow you to output as many templates as you want, regardless of where your template files are located.
Here's a look at the specific usage:
One, the other action template that calls the current module
Format: Display (' Operation name ')
For example, assuming that the current operation is a read operation under the user module, we need to invoke the Edit action template of the user module, using:
Copy the Code code as follows: $this->display (' edit ');
You do not need to write the path and suffix of the template file.
Second, call the operation template of other modules
Format: Display (' Module name: Operation name ')
For example, currently the user module, we need to invoke the Read action template of the member module, using:
Copy the Code code as follows: $this->display (' Member:read ');
This way also does not need to write the template file path and suffix, strictly speaking, the module name and operation name does not necessarily need to have the corresponding module or operation, just a directory name and file name, for example, your project may not have a public module at all, There is no menu operation for the public module, but the same can be used
Copy the Code code as follows: $this->display (' Public:menu ');
Output This template file, understand this, the template output is clear.
Iii. invoking action templates for other topics
Format: Display (' Subject name: module Name: Operation name ')
For example, we need to invoke the Edit action template of the user module of the XP topic, using:
Copy the Code code as follows: $this->display (' Xp:User:edit ');
This way you need to specify the module and operation name
Four, direct full path output template
Format: Display (' template filename ')
For example, we directly output the menu.html template file under the current public directory, using:
Copy the code as follows: $this->display ('./public/menu.html ');
This way you need to specify the template path and suffix, where the public directory is located under the current project portal file location, if it is a different suffix file, also supports direct output, for example:
Copy the code as follows: $this->display ('./public/menu.tpl ');
As long as./PUBLIC/MENU.TPL is a template file that actually exists, if you are using a relative path, be aware that the current location is relative to the entry file for the project, not the template directory.
In fact, the display method has other parameters and usages.
Sometimes a template page we need to output the specified encoding, rather than the default encoding, you can use:
Copy the code as follows: $this->display (' Member:read ', ' GBK ');
or the output template file is not in text/html format, but in XML format, can be used:
Copy the code as follows: $this->display (' Member:read ', ' utf-8 ', ' text/xml ');
If your Web site output encoding is not the default encoding, you can use:
Copy the Code Code as follows: ' Default_charset ' = ' GBK '
If you want to output XML format, you can use:
Copy the Code Code as follows: ' Tmpl_content_type ' = ' text/xml '
If you do not need to render the template file but output the content directly, you can use the Show method, for example:
Copy the code as follows: $this->show ($content, ' utf-8 ', ' text/xml ');
It is hoped that this article will be helpful to everyone's thinkphp framework design.
http://www.bkjia.com/PHPjc/917683.html www.bkjia.com true http://www.bkjia.com/PHPjc/917683.html techarticle thinkphp Template Output Display usage analysis, Thinkphpdisplay This example analyzes the thinkphp template output display usage. Share to everyone for your reference. The specific analysis is as follows: Template variable ...