コード例 #1
0
ファイル: Post.php プロジェクト: giicms/yii2-news
 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;
 }
コード例 #2
0
 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]);
 }