$query, 'pagination' => [ 'pageSize' => 5, ], ] ); return $this->render( 'index', [ 'dataProvider' => $dataProvider, ] ); } public function actionIndex() { $query = Article::find() ->where( [ 'status' => true, ] ) ->orderBy("sort"); return $this->prepareProviderAndRender($query); } public function actionArticle($id) { $model = $this->findModel($id); return $this->render( 'view', [ 'article' => $model, ] ); } protected function findModel($id) { $model = Article::find() ->where( [ 'id' => $id ] ) ->with("lang") ->one(); if ( $model !== NULL) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } public function actionSearch() { if( \Yii::$app->request->isPost ){ $req = \Yii::$app->request; if (!empty($req->post("title"))){ $title = Html::encode($req->post("title")); $query = Article::find() ->joinWith("lang") ->where( [ 'status' => true, ] ) ->andWhere( [ "like", "lower(title)", $title ] ) ->orderBy("sort"); return $this->prepareProviderAndRender($query); } } return $this->redirect(Url::toRoute(['blog/index'])); } public function actionCategory($id) { $query = Article::find() ->joinWith("categories.lang") ->where( [ 'blog_article.status' => true, ] ) ->andWhere( [ "blog_category.id" => $id, "blog_category.status" => true, ] ) ->orderBy("sort"); return $this->prepareProviderAndRender($query); } public function actionTag($id){ $query = Article::find() ->joinWith("tags.lang") ->where( [ 'blog_article.status' => true, 'blog_tag.id' => $id, ] ) ->orderBy('sort'); return $this->prepareProviderAndRender($query); } }