The process of page output in previous versions of thinkphp is to read the template file, and then parse the template (also support the invocation of Third-party template engine parsing), but there are some cases where we do not define the template file, or save the template file in the database, so when the page output, We were unable to read the template file, and the ThinkPHP3.1 version added the function of content parsing output to this situation.
The built-in template engine is also perfected, and if the incoming template file does not exist, it is considered the incoming template parsing content, so the ThinkPHP3.1 version of the view class and the action class also makes some corresponding improvements.
The display method is used for template file render output, the Show method is used for the template content rendering output, and the Show method still supports the content parsing function , so we can use this in the controller:
$this->assign (' name ', ' thinkphp ');
$this->show (' hello,{$name}! ');
The results of the page output are:
You can also read the database by:
$content = M (' Data ')->where ($map)->getfield (' content ');
$this->show ($content);
For the contents of the $content variable, you can support the parsing of variables and tag libraries as well as template files, and you can also support template layout features.
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, you can put the template in the database, for the template management and update is also more convenient.