Home  >  Article  >  Backend Development  >  Detailed explanation of content parsing output of new features of ThinkPHP3.1_PHP tutorial

Detailed explanation of content parsing output of new features of ThinkPHP3.1_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:24:291043browse

The process of page output in previous versions of ThinkPHP was to read the template file and then perform template parsing (it also supports calling third-party template engine parsing). However, in some cases, we did not define the template file or save the template file. In the database, when outputting the page in this case, we cannot read the template file. The ThinkPHP3.1 version adds the function of content parsing and output for this situation.

The built-in template engine has also been improved. If the incoming template file does not exist, it will be considered as the incoming template parsing content. Therefore, the View class and Action class of ThinkPHP version 3.1 have also made some corresponding changes. improvements.

The display method is used for template file rendering output, and the show method is used for template content rendering output, and the show method still supports the content parsing function , so we can use it like this in the controller:

$this->assign('name','ThinkPHP');
$this->show('hello,{$name}!');

The output result of the page is:

hello,ThinkPHP!

You can also read the database:

$content = M('Data')->where($map)->getField('content');
$this->show($content);

For the content in the $content variable, it can support parsing of variables and tag libraries just like template files, and can also support template layout functions.
The show method can also specify the output encoding and type, for example:

$this->show($content,'utf-8','text/xml');

In short, with the show method, the template can be placed in the database, which makes it more convenient to manage and update the template.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825450.htmlTechArticleThe page output process in previous versions of ThinkPHP is to read the template file and then parse the template (it also supports calling the third Third-party template engine parsing), but in some cases, we did not...
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