コード例 #1
0
 /**
  * Finds the Country model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Country the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findCountry($id)
 {
     if (($model = Country::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public function validateCountry()
 {
     if ($this->country_id !== null) {
         $country = Country::findOne($this->country_id);
         if ($country === null) {
             $this->addError('country_id', Yii::t('location', 'Country with id {[id]} doesn\'t exist', ['id' => $this->country_id]));
             return false;
         }
     }
     return true;
 }