コード例 #1
0
 /**
 * Creates data provider instance with search query applied
 *
 * @param array $params
 *
 * @return ActiveDataProvider
 */
 public function search($params)
 {
     $query = CountryModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['SurfaceArea' => $this->SurfaceArea, 'IndepYear' => $this->IndepYear, 'Population' => $this->Population, 'LifeExpectancy' => $this->LifeExpectancy, 'GNP' => $this->GNP, 'GNPOld' => $this->GNPOld, 'Capital' => $this->Capital]);
     $query->andFilterWhere(['like', 'Code', $this->Code])->andFilterWhere(['like', 'Name', $this->Name])->andFilterWhere(['like', 'Continent', $this->Continent])->andFilterWhere(['like', 'Region', $this->Region])->andFilterWhere(['like', 'LocalName', $this->LocalName])->andFilterWhere(['like', 'GovernmentForm', $this->GovernmentForm])->andFilterWhere(['like', 'HeadOfState', $this->HeadOfState])->andFilterWhere(['like', 'Code2', $this->Code2]);
     return $dataProvider;
 }
コード例 #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCountryCode()
 {
     return $this->hasOne(\giiant\world\models\Country::className(), ['Code' => 'CountryCode']);
 }
コード例 #3
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 string $Code
  * @return Country the loaded model
  * @throws HttpException if the model cannot be found
  */
 protected function findModel($Code)
 {
     if (($model = Country::findOne($Code)) !== null) {
         return $model;
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }