/**
  * Creates data provider instance with search query applied
  *
  * @param string $searchQuery
  *
  * @return ActiveDataProvider
  */
 public function search($searchQuery)
 {
     $query = Country::find();
     if ($searchQuery !== null) {
         $query->andFilterWhere(['like', 'name', $searchQuery]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $dataProvider;
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Country::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['population' => $this->population, 'createtime' => $this->createtime]);
     $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCountry()
 {
     return $this->hasOne(Country::className(), ['id' => 'country_id']);
 }
示例#4
0
 public function actionShowlist3($id)
 {
     $contry = \backend\models\Country::find()->where(['Cry_nameTH' => 'ไทย'])->all();
     //$contry = \backend\models\Country::find()->all();
     $fullname2 = '';
     $recid = 0;
     $name = '';
     foreach ($contry as $data2) {
         $recid = $data2->Cry_id;
         $fullname2 = $data2->Cry_nameEN . " [" . $data2->Cry_nameTH . "]";
         $name = $data2->Cry_nameTH;
     }
     if ($name == 'ไทย') {
         echo "<option value='" . $recid . "' selected=true>{$fullname2}</option>";
     } else {
         echo "<option value='" . $recid . "'>{$fullname2}</option>";
     }
 }
 /**
  * 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 $id
  * @return Country the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Country::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#6
0
    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'Name')->textInput(['maxlength' => true]);
?>
    
    <?php 
//     echo $form->field($model, 'CountryCode')->dropdownList(
//         Country::find()->select(['Name', 'Code'])->indexBy('Code')->column(),
//         ['prompt'=>'Select...']);
//     echo $form->field($model, 'CountryCode')->dropdownList(
//         ArrayHelper::map(Country::find()->all(), 'Code', 'Name'),
//         ['prompt'=>'Select...']);
echo $form->field($model, 'CountryCode')->widget(Select2::classname(), ['data' => Country::find()->select(['Name', 'Code'])->indexBy('Code')->column(), 'options' => ['placeholder' => 'Select a code ...'], 'pluginOptions' => ['allowClear' => true]]);
?>

    <?php 
echo $form->field($model, 'District')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'Population')->textInput();
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>