Problems related to local non-cache of smarty custom implementation

Source: Internet
Author: User
Use the plug-in block & nbsp; method to create a file block in the smarty/plugins directory. nocache. php & nbsp; content: & nbsp; & lt ;? Php & nbsp; & n smarty custom implementation without caching
Use the plug-in block method

In the Smarty/plugins directory, create a file block. nocache. php with the following content:

 

Function smarty_block_nocache ($ param, $ content, $ smarty)
{
Return $ content;
}
?>

In the template (smarty has been configured successfully ):

{Nocache}
Non-cached content, such as: {$ smarty. now}
{/Nocache}

According to the above configuration, the content contained in the nocache block should be updated from time to time.
Why can't I update it from time to time in mvc mode?
------ Best solution --------------------
I remember there was an insert in smarty that was dynamically loaded without caching.

------ Other solutions --------------------
1. plug-ins

Specify the name of the function, for example, nocache. Then create a block function under the plugins file. (./Plugins/block. nocache. php) the name of a naming file must comply with the requirements of user-defined functions. In this function, we need to display part of the content of each request so that it will not generate a cache:


Function smarty_block_nocache ($ args, $ content ){

Return $ content ;}

?>

All the plug-ins in smarty are cached by default. Therefore, this file will also be cached. In this case, we need to modify the configuration file Smarty_Compiler.class.php, which will be at the position of row 712 of the file: "$ this-> _ plugins ['block'] [$ tag_command] = array ($ plugin_func, null, true );." Change true in the brackets to false so that all plug-ins will not be automatically generated for caching. If we don't want to change all the plug-ins to a state that is not cached, we just want to keep the block. nocache. php file written to it.

If ($ tag_command = nocache ){

$ This-> _ plugins ['block'] [$ tag_command] = array ($ plugin_func, null, false );}

Else {

$ This-> _ plugins ['block'] [$ tag_command] = array ($ plugin_func, null, true );

}
Thank you for solving this problem.

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.