/** * Finds the City model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return City the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { $model = Yii::$app->db->cache(function ($db) use($id) { return City::findOne($id); }, Yii::$app->params['dbCacheValidTime']); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Получить город по ключу * @param $idCity * @return mixed * @throws \Exception */ public static function getById($idCity) { return Yii::$app->db->cache(function ($db) use($idCity) { return City::findOne($idCity); }, Yii::$app->params['dbCacheValidTime']); }