private function loadModel($id) { $model = \common\models\entities\Announce::findOne(["id" => $id, "status" => 1]); if (!$model) { throw new yii\web\NotFoundHttpException('很抱歉查無資料'); } return $model; }
/** * Finds the Announce model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Announce the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Announce::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.', $this->errorLayout); } }