예제 #1
0
 public function actionCategory()
 {
     $category_id = Yii::$app->request->get('category');
     if (is_null($category_id)) {
         return $this->actionIndex();
     }
     $query = TblBlog::find()->where(['category_id' => $category_id]);
     $page = clone $query;
     $pages = new Pagination(['totalCount' => $query->count()]);
     $pages->setPageSize(5);
     $articles = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
     foreach ($articles as $key => $value) {
         $articles[$key]['text'] = mb_substr($value['text'], 0, 100, 'UTF-8');
     }
     $category = TblCategory::find()->where(['id' => $category_id])->asArray()->one();
     return $this->render('category', ['articles' => $articles, 'category' => $category, 'pages' => $pages]);
 }
예제 #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTblBlogs()
 {
     return $this->hasMany(TblBlog::className(), ['category_id' => 'id']);
 }
예제 #3
0
 /**
  * Finds the TblBlog model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return TblBlog the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = TblBlog::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }