/** * Lists all Posts models. * @return mixed */ public function actionIndex() { $AllPosts = Posts::find()->all(); if ($AllPosts) { return $this->render('index', ['posts' => $AllPosts]); } }
/** * Lists all Posts models. * @return mixed */ public function actionIndex() { $AllPosts = Posts::find(); if ($AllPosts) { $pages = new Pagination(['totalCount' => $AllPosts->count(), 'pageSize' => 9]); $posts = $AllPosts->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('index', ['posts' => $posts, 'pages' => $pages]); } }
/** * Lists all Posts models. * @return mixed */ public function actionIndex() { // $searchModel = new PostsSearch(); // $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $AllPosts = Posts::find(); print_r($AllPosts); if ($AllPosts) { $pages = new Pagination(['totalCount' => $AllPosts->count(), 'pageSize' => 9]); $posts = $AllPosts->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('index', ['posts' => $posts, 'pages' => $pages]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Posts::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, 'text' => $this->text]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'text_preview', $this->text_preview])->andFilterWhere(['like', 'img', $this->img]); return $dataProvider; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(Request $request, $id) { $post = Posts::find($id); if ($post && ($post->author_id == $request->user()->id || $request->user()->is_admin())) { $files = DB::table('post_uploads')->where('post_id', '=', $post->id)->get(); foreach ($files as $file) { File::delete('../app/Modules/Blog/myupload/' . $post->id . "/" . $file->media_name); } $post->delete(); $data['message'] = 'Post deleted Successfully'; } else { $data['errors'] = 'Invalid Operation. You have not sufficient permissions'; } return redirect('/posts')->with($data); }