Home  >  Article  >  Backend Development  >  How to enable fragment caching in Yii, enable fragments in yii_PHP tutorial

How to enable fragment caching in Yii, enable fragments in yii_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:55:09908browse

How to enable fragment caching in Yii, enable fragments in yii

The example in this article describes how to enable fragment caching in Yii. Share it with everyone for your reference, the details are as follows:

1. Add:

to the components in the main.php file
cache'=>array(
    'class'=>'system.caching.CFileCache',
),

2. Add this sentence wherever caching is needed in the view

<&#63;php if($this->beginCache('aaa',
    array(
      'duration'=>3360,
      'varyByParam'=>array('page'),
      'dependecy'=>array(
        'class'=> 'system.caching.CDbCacheDependency',
        'sqll'=>'select count(server) from {{game_serve}}' ,
        //设置依赖缓存,如果这个语句变化了,缓存跟新
      ),
    )
  )
){
//这里是没有缓存走的,上面设置缓存时间,并且设置变化缓存,如果没有分页就不需要最后一个参数
}
&#63;>
//结束缓存这里,当没有缓存的时候走下面这if结尾也会缓存住信息,当前缓存在runtime文件夹中

Readers who are interested in more Yii-related content can check out the special topics on this site: "Introduction to Yii Framework and Summary of Common Techniques", "Summary of Excellent PHP Development Framework", "Basic Tutorial for Getting Started with Smarty Templates", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

Articles you may be interested in:

  • YII Framework filter usage analysis
  • Introduction to some advanced usage of caching in PHP's Yii framework
  • In-depth analysis of the caching function in PHP's Yii framework
  • Advanced use of View in PHP's Yii framework
  • Study tutorial on Model model in PHP's Yii framework
  • Detailed explanation Controller controller in PHP's Yii framework
  • Yii database cache instance analysis
  • Detailed explanation of attribute injection and method injection of component behavior in PHP's Yii framework
  • Detailed explanation in PHP's Methods of using Behaviors in Yii Framework
  • YII Framework learning request and response usage (based on CHttpRequest response)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1117091.htmlTechArticleHow to enable fragment caching in Yii, enable fragments in yii. This article describes how to enable fragment caching in Yii. Share it with everyone for your reference, the details are as follows: 1. comp...
in the main.php file
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn