1 <?php 2 namespace appcontrollers; 3 use yiiwebController; 4 5 6 class HelloController extends Controller { 7 public function behaviors() { 8 return[ 9 [ 10 'class'=>'yiifiltersPageCache', //页面缓存 11 'duration'=>1000,//缓存时间 12 'only'=>['index','test'], //缓存的页面 13 'dependency'=>[ //缓存依赖 14 'class'=>'yiicachingFileDependency', 15 'fileName'=>'hw.txt' 16 ] 17 ] 18 ]; 19 } 20 public function actionIndex() 21 { 22 echo '5'; 23 // return $this->render('index'); 24 } 25 public function actionTest() { 26 echo '4'; 27 } 28 }
其中 behaviors() 方法会优先于其它的function