|
5 | 5 | use yii\widgets\ListView; |
6 | 6 | use frontend\components\TagsCloudWidget; |
7 | 7 | use frontend\components\RctReplyWidget; |
| 8 | +use common\models\Post; |
| 9 | +use yii\caching\DbDependency; |
| 10 | +use yii\caching\yii\caching; |
8 | 11 |
|
9 | 12 | /* @var $this yii\web\View */ |
10 | 13 | /* @var $searchModel common\models\PostSearch */ |
|
43 | 46 | <div class="searchbox"> |
44 | 47 | <ul class="list-group"> |
45 | 48 | <li class="list-group-item"> |
46 | | - <span class="glyphicon glyphicon-search" aria-hidden="true"></span> 查找文章 |
| 49 | + <span class="glyphicon glyphicon-search" aria-hidden="true"></span> 查找文章( |
| 50 | + <?php |
| 51 | + //数据缓存示例代码 |
| 52 | + /* |
| 53 | + $data = Yii::$app->cache->get('postCount'); |
| 54 | + $dependency = new DbDependency(['sql'=>'select count(id) from post']); |
| 55 | + |
| 56 | + if ($data === false) |
| 57 | + { |
| 58 | + $data = Post::find()->count(); sleep(5); |
| 59 | + Yii::$app->cache->set('postCount',$data,600,$dependency); //设置缓存60秒后过期 |
| 60 | + } |
| 61 | + |
| 62 | + echo $data; |
| 63 | + */ |
| 64 | + ?> |
| 65 | + <?= Post::find()->count();?> |
| 66 | + ) |
47 | 67 | </li> |
48 | 68 | <li class="list-group-item"> |
49 | | - <form class="form-inline" action="index.php?r=post/index" id="w0" method="get"> |
| 69 | + <form class="form-inline" action="<?= Yii::$app->urlManager->createUrl(['post/index']);?>" id="w0" method="get"> |
50 | 70 | <div class="form-group"> |
51 | 71 | <input type="text" class="form-control" name="PostSearch[title]" id="w0input" placeholder="按标题"> |
52 | 72 | </div> |
|
63 | 83 | <span class="glyphicon glyphicon-tags" aria-hidden="true"></span> 标签云 |
64 | 84 | </li> |
65 | 85 | <li class="list-group-item"> |
66 | | - <?= TagsCloudWidget::widget(['tags'=>$tags])?> |
| 86 | + <?php |
| 87 | + //片段缓存示例代码 |
| 88 | + /* |
| 89 | + $dependency = new DbDependency(['sql'=>'select count(id) from post']); |
| 90 | + |
| 91 | + if ($this->beginCache('cache',['duration'=>600],['dependency'=>$dependency])) |
| 92 | + { |
| 93 | + echo TagsCloudWidget::widget(['tags'=>$tags]); |
| 94 | + $this->endCache(); |
| 95 | + } |
| 96 | + */ |
| 97 | + ?> |
| 98 | + <?= TagsCloudWidget::widget(['tags'=>$tags]);?> |
67 | 99 | </li> |
68 | 100 | </ul> |
69 | 101 | </div> |
|
0 commit comments