Inheritance: extends Post
Example #1
0
 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex($id = 0)
 {
     if ($id > 0) {
         $query = Post::find()->where(['category' => $id]);
         //die(print_r($query));
         $pages = new Pagination(['totalCount' => Post::find()->where(['category' => $id])->count(), 'pageSize' => 8]);
         $posts = $query->offset($pages->offset)->limit($pages->limit)->all();
         $all_posts = new ActiveDataProvider(['query' => $query->offset($pages->offset)->limit($pages->limit)->all()]);
         /*$all_posts = new ActiveDataProvider([
               'query' => Post::find(),
               'pagination' => [
                   'totalCount' => $countQuery->count(),
                   'pageSize' => 5
               ],
           ]);*/
         return $this->render('index', ['allPosts' => $all_posts, 'pages' => $pages, 'posts' => $posts]);
     } else {
         $searchModel = new PostSearch();
         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
         $query = Post::find();
         $countQuery = clone $query;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 8]);
         $posts = $query->offset($pages->offset)->limit($pages->limit)->all();
         $all_posts = new ActiveDataProvider(['query' => $query->offset($pages->offset)->limit($pages->limit)->all()]);
         /*$all_posts = new ActiveDataProvider([
               'query' => Post::find(),
               'pagination' => [
                   'totalCount' => $countQuery->count(),
                   'pageSize' => 5
               ],
           ]);*/
         return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'allPosts' => $all_posts, 'pages' => $pages, 'posts' => $posts]);
     }
 }
Example #2
0
 /**
  * 话题列表
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PostSearch();
     // 话题或者分类筛选
     $params = Yii::$app->request->queryParams;
     empty($params['tag']) ?: ($params['PostSearch']['tags'] = $params['tag']);
     if (isset($params['node'])) {
         $postMeta = PostMeta::findOne(['alias' => $params['node']]);
         $postMeta ? $params['PostSearch']['post_meta_id'] = $postMeta->id : '';
     }
     $dataProvider = $searchModel->search($params);
     $dataProvider->query->andWhere([Post::tableName() . '.type' => 'topic', 'status' => [Post::STATUS_ACTIVE, Post::STATUS_EXCELLENT]]);
     // 排序
     $sort = $dataProvider->getSort();
     $sort->attributes = array_merge($sort->attributes, ['hotest' => ['asc' => ['comment_count' => SORT_DESC, 'created_at' => SORT_DESC]], 'excellent' => ['asc' => ['status' => SORT_DESC, 'comment_count' => SORT_DESC, 'created_at' => SORT_DESC]], 'uncommented' => ['asc' => ['comment_count' => SORT_ASC, 'created_at' => SORT_DESC]]]);
     return $this->render('index', ['searchModel' => $searchModel, 'sorts' => $this->sorts, 'dataProvider' => $dataProvider]);
 }
Example #3
0
 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new PostSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Example #4
0
 public function actionAdmin()
 {
     $user_id = yii::$app->getUser()->id;
     $params = array_merge(Yii::$app->request->queryParams, ['PostSearch' => ['user_id' => $user_id]]);
     $user_name = Member::findIdentity($user_id)->name;
     $title = '用户' . $user_name . '下的日志';
     $searchModel = new PostSearch();
     $dataProvider = $searchModel->search($params);
     return $this->render('admin', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'title' => $title]);
 }