Yii Framework Official Guide Series 32--cache: Dynamic Content

Source: Internet
Author: User



When using fragment caching or page caching, we often encounter such situations where the output of the entire section is static except for individual places. For example, the help page might display static help information, while the user name shows the current user.

To solve this problem, we can match the cached content according to the username, but it will be a huge waste of our precious space, because the cache is the same for most other things except the user name. We can also cut pages into fragments and cache them separately, but that can complicate the page and code. A better approach is to use dynamic content functionality provided by [Ccontroller].

Dynamic content means that the fragment output is not cached even in the content that is included in the fragment cache. Even if the included content is taken out of the cache, it must be regenerated each time to make the dynamic content dynamic at all times. For this reason, we require dynamic content to be generated through some methods or functions.

Call Ccontroller::renderdynamic () to insert dynamic content where you want.


... Other HTML content ... <?php if ($this->begincache ($id)) {... Cached fragment content    ... <?php $this->renderdynamic ($callback); Cached fragment content ... <?php $this->endcache (); } ..... Other HTML content ...

In the above, $callback it refers to a valid PHP callback. It can be either a method that points to the current controller class or a string name for a global function. It can also be an array name that points to a method of a class. Any other parameters will be passed to the Renderdynamic () method. The callback returns dynamic content instead of just displaying it.


The above is the official Yii Framework Guide Series 32--cache: Dynamic content content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.