Пример #1
0
 public function get_category()
 {
     $data = TblCategory::find()->all();
     $category = [];
     foreach ($data as $key => $value) {
         $tmp = $value->attributes;
         $category[$tmp['id']] = $tmp['name'];
     }
     return $category;
 }
Пример #2
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]);
 }
Пример #3
0
 /**
  * Lists all TblCategory models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => TblCategory::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }