Exemplo n.º 1
0
 public function actionBycategory($category_id)
 {
     $cat = new Category();
     $model = $cat->findOne($category_id);
     $category_title = $model->name;
     $dataProvider = new ActiveDataProvider(['query' => Post::find()->where(['status' => 1, 'category_id' => $category_id])->with('category')->orderBy('created_at DESC'), 'pagination' => ['pageSize' => 10]]);
     return $this->render('categoryindex', ['listDataProvider' => $dataProvider, 'category_title' => $category_title]);
 }
Exemplo n.º 2
0
 /**
  * Lists all Post models.
  * @return mixed
  */
 public function actionIndex()
 {
     $allPost = Post::find();
     if ($allPost) {
         $pages = new Pagination(['totalCount' => $allPost->count(), 'pageSize' => 3]);
         $posts = $allPost->offset($pages->offset)->limit($pages->limit)->all();
         return $this->render('index', ['posts' => $posts, 'pages' => $pages]);
     }
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Post::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'category_id' => $this->category_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Exemplo n.º 5
0
 /**
  * Возвращает количество опубликованых постов в категории
  * @param $id
  * @return integer
  */
 public function getCountPosts($id)
 {
     $count = Post::find()->select(['COUNT(*) AS cnt'])->where(['category_id' => $id, 'publish_status' => Post::STATUS_PUBLISH])->count();
     return $count;
 }
Exemplo n.º 6
0
 /**
  * Возвращает архивные посты с пагинацией
  * @param $archive
  * @return array
  */
 public function getArchivePosts($archive = null)
 {
     $query = Post::find()->where(['publish_status' => self::STATUS_ARCHIVE])->orderBy(['id' => SORT_DESC]);
     // Сортировать по id
     $query->andFilterWhere(['>=', 'created_at', strtotime($archive . '-01 00:00:00') ? strtotime($archive . '-01 00:00:00') : null])->andFilterWhere(['<=', 'created_at', strtotime($archive . '-31 23:59:59') ? strtotime($archive . '-31 23:59:59') : null]);
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => \Yii::$app->getModule('blog')->pageSize]);
     $posts = $query->offset($pages->offset)->limit($pages->limit)->all();
     return ['posts' => $posts, 'pages' => $pages];
 }
Exemplo n.º 7
0
 public function actionIndex()
 {
     $models = Post::find()->all();
     return $this->render('index', ['models' => $models]);
 }