Beispiel #1
0
 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex()
 {
     $modelCategory = Category::find()->getActive()->all();
     $modelPosts = Post::find()->orderBy(['created_at' => SORT_DESC])->with(['category' => function ($q) {
         $q->getActive();
     }]);
     if ($modelPosts) {
         $pages = new Pagination(['totalCount' => $modelPosts->count(), 'pageSize' => 3]);
         $pages->pageSizeParam = false;
         $posts = $modelPosts->offset($pages->offset)->limit($pages->limit)->all();
         return $this->render('index', ['posts' => $posts, 'pages' => $pages, 'modelCategory' => $modelCategory]);
     }
 }
Beispiel #2
0
 function run()
 {
     $cacheId = $this->timec . 'post';
     $baseQuery = Post::find()->select(['id', 'title'])->orderBy('created_at');
     if (($modelsPrev = Yii::$app->cache->get($cacheId . 'prev')) === false) {
         $modelsPrev = $baseQuery->where(['>', 'created_at', $this->timec])->one();
         Yii::$app->cache->set($cacheId . 'prev', $modelsPrev, 3600);
     }
     if (($modelsNext = Yii::$app->cache->get($cacheId . 'next')) === false) {
         $modelsNext = $baseQuery->where(['<', 'created_at', $this->timec])->orderBy('created_at DESC')->one();
         Yii::$app->cache->set($cacheId . 'next', $modelsNext, 3600);
     }
     return $this->render('PaginationPrevNext', compact('modelsPrev', 'modelsNext'));
 }
Beispiel #3
0
 function run()
 {
     $modelsPrev = Post::find()->where(['>', 'created_at', $this->timec])->select(['id', 'title'])->limit(1)->orderBy('created_at')->all();
     $modelsNext = Post::find()->where(['<', 'created_at', $this->timec])->select(['id', 'title'])->limit(1)->orderBy('created_at DESC')->all();
     return $this->render('PaginationPrevNext', compact('modelsPrev', 'modelsNext'));
 }