Static page generation for thinkphp mixed coding

Source: Internet
Author: User
Static pages are especially important for a website that is not updated frequently. when the website is too large and has a high access volume, the website can be opened too slowly or even cannot be opened.

Static pages are especially important for a website that is not updated frequently. when the website is too large and has a high access volume, the website can be opened too slowly or even cannot be opened, of course, when the user sees that the website cannot be opened, the webpage will be shut down. so I have studied static methods. of course thinkphp also has its own method, so I won't talk about it.

Write in the action of the page to be static

Action method


Ob_start ();
$ Static_file = './home/Tpl/default/Index/s.html'; // static page
$ Path = './IndexAction. class. php ';
$ Php_file = basename ($ path); // The current dynamic page
If (! File_exists ($ static_file) |
(Filemtime ($ static_file) + 1800) <time () | // fixed cache time
Filemtime ($ php_file)> filemtime ($ static_file) // you can determine whether the source file has been modified.
{

// The following is the logic in your own action.
$ User = M ('user ');
$ Tupian = M ('tupianshangchuan ');
$ Tupian = $ tupian-> select ();
$ List = $ user-> where ('email = "'. Session: get ('email'). '"')-> select ();
$ This-> assign ('tupian', $ tupian );
$ This-> assign ('list', $ list );
$ This-> display (s_index );
$ C = ob_get_contents ();
File_put_contents ($ static_file, $ c );
} Else {
$ This-> display ('s ');
}


 

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.