Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 /**
  * Renders the index view for the module
  * @return string
  */
 public function actionIndex()
 {
     $model = Post::find()->all();
     return $this->render('index', ['model' => $model]);
 }
Exemplo n.º 3
0
 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]);
 }
Exemplo n.º 4
0
 /**
  * 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.');
     }
 }