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)!