public function run() { $out = ''; $countryDropdown = Select2::widget(['name' => 'country', 'value' => '', 'data' => Country::dropdown(), 'options' => ['label' => 'yaya', 'placeholder' => 'Select Country ...', 'id' => 'country-selection']]); $locationDropdown = $this->form->field($this->model, 'location_id')->label(false)->widget(DepDrop::classname(), ['type' => DepDrop::TYPE_SELECT2, 'options' => ['id' => 'location-selection'], 'select2Options' => ['pluginOptions' => ['allowClear' => TRUE]], 'pluginOptions' => ['depends' => ['country-selection'], 'placeholder' => 'Select Location', 'url' => Url::to(['/location/admin/load'])]]); $this->_printField($countryDropdown, $out); $this->_printField($locationDropdown, $out); return $out; }
protected function _query() { $query = Country::find(); $currentLanguage = substr(Translation::current(), 0, 2); $local = new Expression("'{$currentLanguage}'"); $fallbackLanguage = substr(Translation::fallback(), 0, 2); $fallback = new Expression("'{$fallbackLanguage}'"); $query->leftJoin('country_translation default_label', "(`country`.`iso_2`=`default_label`.`country_id` AND {$fallback}=`default_label`.`language_id`)"); $query->leftJoin('country_translation localised_label', "(`country`.`iso_2`=`localised_label`.`country_id` AND {$local} =`localised_label`.`language_id`)"); $query->select = ['code' => 'iso_2', 'label' => 'CONCAT(IF(localised_label.common_name IS NULL, default_label.common_name,localised_label.common_name),\' (\',iso_2,\')\')', 'has_postcodes' => 'has_postcodes', 'common_name' => 'IF(localised_label.common_name IS NULL, default_label.common_name,localised_label.common_name)', 'official_name' => 'IF(localised_label.official_name IS NULL, default_label.official_name,localised_label.official_name)', 'common' => 'IF(localised_label.common_name IS NULL, default_label.common_name,localised_label.common_name)', 'official' => 'IF(localised_label.official_name IS NULL, default_label.official_name,localised_label.official_name)']; $query->groupBy('code'); return $query; }
/** * @return \yii\db\ActiveQuery */ public function getCountry() { return $this->hasOne(Country::className(), ['iso_2' => 'country_id']); }
public function actionDummyData() { $countries = \humanized\location\models\location\Country::find()->select('iso_2')->asArray()->all(); foreach ($countries as $country) { $countryId = $country['iso_2']; $this->_dummyLocation($countryId, '!UNSET', '0'); $this->_dummyLocation($countryId, '!UNKNOWN', '-1'); } }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use humanized\location\models\location\Country; /* @var $this yii\web\View */ /* @var $model humanized\contact\models\location\CitySearch */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="city-search"> <?php $form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']); ?> <div class="row"> <div class="col-sm-3"> <?php echo $form->field($model, 'country_id')->label(false)->dropDownList(Country::dropdown(), ['onChange' => 'this.form.submit()']); ?> </div> </div> <?php ActiveForm::end(); ?> </div>
/** * 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 findModel($id) { if (($model = Country::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function getCountryList($params) { return Country::find()->asArray()->all(); }