public function init() { parent::init(); $query = \app\models\CountryList::find()->with('countries', 'continents')->asArray()->all(); if ($this->message === null) { $this->message = json_encode($query); } else { $this->message = 'Welcome dszfgsdf' . $this->message; } }
/** * Lists all CountryList models. * @return mixed */ public function actionIndex() { $query = \app\models\CountryList::find()->joinWith('countries', 'continents'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => ['countries.name', 'continents.name', 'currency_code', 'continents.name' => ['asc' => ['name' => SORT_ASC], 'desc' => ['name' => SORT_DESC], 'default' => SORT_DESC], 'countries.name' => ['asc' => ['name' => SORT_ASC], 'desc' => ['name' => SORT_DESC], 'default' => SORT_DESC], 'countries.currency_code' => ['asc' => ['currency_code' => SORT_ASC], 'desc' => ['currency_code' => SORT_DESC], 'default' => SORT_DESC]]], 'pagination' => ['pageSize' => Yii::getAlias('@paging')]]); return $this->render('index', ['dataProvider' => $dataProvider]); }
public function actionContinent_country($param = '') { $countriesStr = ''; if ($_REQUEST["code"] != "") { $contylist = CountryList::find()->filterWhere(['country_list.continents_code' => $_REQUEST["code"]])->asArray()->all(); if (count($contylist) > 0) { $ctr = 0; foreach ($contylist as $country) { $countries = Countries::find()->filterWhere(['countries.code' => $country["countries_code"]])->asArray()->all(); if ($ctr == 0) { $currency = $countries[0]['currency_code']; } $countriesStr .= "<option value='" . $countries[0]['code'] . "'>" . $countries[0]['name'] . "</option>"; $ctr++; } } else { $countriesStr = "<option>-</option>"; } } else { $countriesStr = "<option>Select Country</option>"; $currency = ''; } $data = array("country" => $countriesStr, "currency" => $currency); echo json_encode($data); }