/**
  * 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 findCity($id)
 {
     if (($model = City::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function validateCity()
 {
     if ($this->city_id !== null) {
         $city = City::findOne($this->city_id);
         if ($city === null) {
             $this->addError('city_id', Yii::t('location', 'City with id {[id]} doesn\'t exist', ['id' => $this->city_id]));
             return false;
         }
         $this->region_id = $city->region_id;
     }
     return true;
 }