/**
  * Evaluates the value of the user.
  * The return result of this method will be assigned to the current attribute(s).
  * @param Event $event
  * @return mixed the value of the user.
  */
 protected function getValue($event)
 {
     $attribute = $this->countryAttribute;
     $value = $this->owner->{$attribute};
     if (is_numeric($value)) {
         return $value;
     } else {
         if (empty($value)) {
             return NULL;
         } else {
             $model = new Country(['name' => $value, 'status' => Country::STATUS_ACTIVE]);
             return $model->save(FALSE) ? $model->id : 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, 'pagination' => ['pageSize' => 50]]);
     $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(['id' => $this->id]);
     $query->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'abbreviation', $this->abbreviation]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCountry()
 {
     return $this->hasOne(Country::className(), ['id' => 'country_id']);
 }
Example #4
0
?>

	<?php 
echo $form->field($model, 'subdistrict_id')->widget(DepDrop::classname(), ['data' => [], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['multiple' => FALSE, 'allowClear' => TRUE, 'tags' => TRUE, 'maximumInputLength' => 255]], 'pluginOptions' => ['initialize' => TRUE, 'placeholder' => 'Select or type subdistrict', 'depends' => ['postcodeform-district_id'], 'url' => Url::to(['/region/subdistrict/depdrop-options', 'selected' => $model->subdistrict_id]), 'loadingText' => 'Loading subdistricts ...']]);
?>
	<?php 
echo $form->field($model, 'district_id')->widget(DepDrop::classname(), ['data' => [], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['multiple' => FALSE, 'allowClear' => TRUE, 'tags' => TRUE, 'maximumInputLength' => 255]], 'pluginOptions' => ['initialize' => TRUE, 'placeholder' => 'Select or type district', 'depends' => ['postcodeform-city_id'], 'url' => Url::to(['/region/district/depdrop-options', 'selected' => $model->city_id]), 'loadingText' => 'Loading districts ...']]);
?>
	<?php 
echo $form->field($model, 'city_id')->widget(DepDrop::classname(), ['data' => [], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['multiple' => FALSE, 'allowClear' => TRUE, 'tags' => TRUE, 'maximumInputLength' => 255]], 'pluginOptions' => ['initialize' => TRUE, 'placeholder' => 'Select or type city', 'depends' => ['postcodeform-province_id'], 'url' => Url::to(['/region/city/depdrop-options', 'selected' => $model->city_id]), 'loadingText' => 'Loading cities ...']]);
?>
	<?php 
echo $form->field($model, 'province_id')->widget(DepDrop::classname(), ['data' => [], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['multiple' => FALSE, 'allowClear' => TRUE, 'tags' => TRUE, 'maximumInputLength' => 255]], 'pluginOptions' => ['initialize' => TRUE, 'placeholder' => 'Select or type province', 'depends' => ['postcodeform-country_id'], 'url' => Url::to(['/region/province/depdrop-options', 'selected' => $model->province_id]), 'loadingText' => 'Loading provinces ...']]);
?>
	<?php 
echo $form->field($model, 'country_id')->widget(Select2::classname(), ['data' => Country::asOption(), 'pluginOptions' => ['placeholder' => 'Select or type Country', 'multiple' => FALSE, 'allowClear' => TRUE, 'tags' => TRUE, 'maximumInputLength' => 255]]);
?>

	<div class="form-group">
		<?php 
echo Html::submitButton('Search', ['class' => 'btn btn-primary']);
?>
		<?php 
echo Html::resetButton('Reset', ['class' => 'btn btn-default']);
?>
	</div>

	<?php 
ActiveForm::end();
?>
 /**
  * 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 HttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Country::findOne($id)) !== null) {
         return $model;
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }