thinkphp templates do not resolve direct-output solutions _javascript tips

Source: Internet
Author: User
Tags constant

The example in this article describes a workaround for the thinkphp template that does not parse the output directly. Share to everyone for your reference. Specifically as follows:

First, the question:

Recently in the Learning thinkphp template, but found that the template page is out, after a hard search finally found a solution.

Second, the solution:

Many people have the same problem, the __root__, __public__, __app__, which are included in the string assigned to the variable, are replaced with the real path when displayed in the template. In other words, this problem was discovered when writing a Timi file management system.

From the file to read out the source code output to the page, as long as the TP path characters, are replaced by the real path.
Like what:

Copy Code code as follows:
$this->assign (' filecontent ', $fileContent);//$fileContent contains the __public__ "path constant" character.


The page output is displayed as the true path/public/.
During the period after a variety of attempts, such as assign Base64 encryption, template output when decode, found no effect. Finally can not help to see the next TP this block of source code, found in the display method of the last step by calling the tag method to "TP path constant" to replace the real path. is normal before the Render method.

Originally intended to change the source code to achieve the following demand for the child's Shoes program:
Boss, is this a temporary solution or a final solution?
But I feel it's okay to add a judgment to the Assign () method,
If it is $this->assign (",", false), the content is not replaced, the output is as is.

As a result, after reading this source, it is not so easy, the changes are too big.

Finally, another child shoes reply, point 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 the __public__ strings on the page are replaced, so if you really need to output the __public__ string to the template, we can add the substitution rule by adding a way, for example:

Copy Code code as follows:
' Tmpl_parse_string ' =>array (
'--public--' => ' __public__ ',//output/public string with new rule
)

With this addition to the replacement rule, if we want to output the __public__ string, we simply add--public--to the template, and the other replacement strings are exported in a similar way.

With this addition to the replacement rule, if we want to output the __public__ string, we simply add--public--to the template, and the other replacement strings are exported in a similar way.

So the plan comes out:

Configured in the configuration file config.php of TP

Copy Code code as follows:
' Tmpl_parse_string ' => array (//path configuration

Timi File path restore
'--public--' => ' __public__ ',
'--app--' => ' __app__ ',
'--url--' => ' __url__ ',
'--action--' => ' __action__ ',
'--self--' => ' __self__ ',
'--info--' => ' __info__ ',
'--ext--' => ' __ext__ '
),

When you read the source code, replace the "path constant character" __root__ as--root--:

Copy Code code as follows:
$fileContent =file_get_contents ($filePath);
$fileContent =htmlspecialchars (preg_replace) ('/__ (. *?) __/is ', '--$1--', $fileContent));

The tmpl_parse_string configuration is then replaced when the template is parsed, as shown in the following figure:

As a matter of time, the problem was solved "temporarily" and "perfectly".

I hope this article will be helpful to everyone's thinkphp framework program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.