/** * Lists all Article models. * @return mixed */ public function actionIndex() { // Выводим статьи в обратном порядке $query = Article::find()->where(['status_id' => Yii::$app->params['status']['active']])->orderBy('created_at DESC'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Yii::$app->params['article']['pageSize']]); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('index', ['models' => $models, 'pages' => $pages]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Article::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'weight' => $this->weight, 'status_id' => $this->status_id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'preview', $this->preview])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'category_id', $this->category_id])->andFilterWhere(['like', 'tag', $this->tag]); return $dataProvider; }
public function actionIndex() { return $this->render('index', ['dataProvider' => new ActiveDataProvider(['query' => Article::find()->where('"name" is null')->orderBy(['id' => SORT_DESC]), 'pagination' => ['pageSize' => 14]])]); }
public function actionIndex() { return $this->render('index', ['statistics' => $this->renderPartial('statistics', ['statistics' => static::statistics()]), 'news' => Article::find()->where('"name" is null')->orderBy(['id' => SORT_DESC])->limit(3)->all()]); }