/** * Finds the Post model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Post the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Post::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionModeratepost() { if (!\Yii::$app->request->isAjax) { return $this->run('site/error'); } \Yii::$app->response->format = 'json'; $post = Post::findOne(['id' => \Yii::$app->request->post("post")]); if (!$post) { return $this->run('site/error'); } $post->show = $post->show == 1 ? 0 : 1; $post->save(false); return $post->show; }