public function getCategory() { $post = Post::findOne($this->id); foreach (explode(',', $post->category_id) as $value) { $category = Category::findOne($value); if (!empty($category)) { $data[] = ['id' => $category->id, 'parent_id' => $category->parent_id, 'title' => $category->title, 'indent' => $this->getIndent($category->indent)]; } } return $data; }
public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Post::find()->where(['type' => 'news'])->orderBy('id DESC'), 'pagination' => ['pageSize' => 10]]); $this->view->title = 'News'; return $this->render('index', ['dataProvider' => $dataProvider]); }