The example in this article describes the solution to the problem that the Thinkphp template is not parsed and directly outputs it as it is. Share it with everyone for your reference. The details are as follows:
1. Question:
I was learning thinkphp templates recently, but I found that the template page came out as it was. After some hard searching, I finally found the solution.
2. Solution:
Many people have encountered the same problem. The __ROOT__, __PUBLIC__, and __APP__ contained in the string assigned to the variable are replaced with real paths when displayed in the template. I discovered this problem while writing the Timi file management system.
After reading the source code from the file and outputting it to the page, I found that as long as it is a TP path character, it has been replaced with a real path.
For example:
I originally planned to change the source code to implement the following solution for children’s shoes:
Boss, is this a temporary solution or a final solution?
But I think it’s not bad to add a judgment in the assign() method,
If it is $this->assign('','',false), the content will not be replaced and will be output as is.
As a result, after reading this source code, I realized that it was not that easy and the changes were too big.
The last reply from another child pointed out the final solution:
"You can refer to the content here: http://www.jb51.net/article/54217.htm(template replacement)
With the template replacement rule, all __PUBLIC__ strings on the page will be replaced. If we really need to output the __PUBLIC__ string to the template, we can add replacement rules, for example:
After adding the replacement rules in this way, if we want to output the __PUBLIC__ string, we only need to add --PUBLIC-- in the template. The output method of other replacement strings is similar.
So, the plan was released:
Configure in Tp’s configuration file config.php
Then the configuration of TMPL_PARSE_STRING is just replaced when the template is parsed, as shown in the figure below:
Ever since, this problem has been "temporarily" and "perfectly" solved.
I hope this article will be helpful to everyone’s ThinkPHP framework programming.