/** * @inheritdoc */ public function init() { parent::init(); if ($this->key) { $model = Content::findOne(['key' => $this->key]); if (null !== $model) { echo $model->content; } else { return null; // throw new InvalidValueException('Content not found'); } } else { throw new InvalidParamException('Invalid content key'); } }
/** * Finds the Content model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Content the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Content::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }