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; }
/** * Renders the index view for the module * @return string */ public function actionIndex() { $model = Post::find()->all(); return $this->render('index', ['model' => $model]); }
public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Post::find()->orderBy('id DESC'), 'pagination' => ['pageSize' => 10]]); $this->view->title = 'Forum'; return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Finds the Post model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Post the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Post::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }