public function actionCategoryIndex($slug) { $blogCategory = $this->findBlogCategory($slug); $query = BlogPost::find()->joinWith('translations')->joinWith('blogCategory.translations')->where(['is_published' => true])->andWhere(['<>', 'blog_post_lang.slug', ''])->andWhere(['blog_post_lang.language' => Yii::$app->language])->andWhere(['blog_category_lang.slug' => $blogCategory->slug])->orderBy(['created_at' => SORT_DESC]); $blogPostProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['forcePageParam' => false, 'defaultPageSize' => 10]]); return $this->render('category-index', compact('blogPostProvider', 'blogCategory')); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = BlogPost::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, 'is_published' => $this->is_published, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); return $dataProvider; }
public function actions() { return ['index' => ['class' => IndexAction::className(), 'query' => BlogPost::find()], 'update' => ['class' => UpdateAction::className(), 'modelClass' => BlogPost::className()], 'delete' => ['class' => DeleteAction::className(), 'modelClass' => BlogPost::className()]]; }