public function actionIndex() { $query = TblBlog::find(); $hotquery = clone $query; $hots = $hotquery->select(['id', 'title'])->orderBy('pri desc')->limit(3)->asArray()->all(); $pages = new Pagination(['totalCount' => $query->count()]); $pages->setPageSize(5); $articles = $query->offset($pages->offset)->limit($pages->limit)->orderBy('id DESC')->asArray()->all(); foreach ($articles as $key => $value) { $articles[$key]['text'] = mb_substr($value['text'], 0, 100, 'UTF-8'); } $motto = TblMotto::getrandmotto(); $categories = TblCategory::find()->asArray()->all(); return $this->render('index', ['articles' => $articles, 'motto' => $motto, 'pages' => $pages, 'hots' => $hots, 'categories' => $categories]); }
/** * Finds the TblMotto model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return TblMotto the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TblMotto::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }