public function getCityFromIp() { $controller = $this->owner; $session = Yii::$app->session; $city = ''; if (!$session->isActive) { $session->open(); } $cookCityUrl = Yii::$app->request->cookies->getValue('city_url'); if (Yii::$app->request->get('city_url')) { $city = City::findOne(['trans' => Yii::$app->request->get('city_url')]); } elseif ($cookCityUrl) { $city = City::findOne(['trans' => $cookCityUrl]); } else { $geo = new Geo(); $data = $geo->get_value(); if (!empty($data)) { //если не определился город подставляем москву $city = City::findOne(['name' => $data['city']]); } } if (empty($city)) { $city = City::findOne(['name' => 'Москва']); } Yii::$app->response->cookies->add(new \yii\web\Cookie(['name' => 'city_url', 'value' => $city->trans])); /* $session->set('xy', $city->xy); $session->set('city', $city->name); $session->set('city_trans', $city->trans); */ $controller->xy = $city->xy; $controller->city = $city->name; $controller->city_url = $city->trans; $controller->city_padezh = $city->padezh; Yii::$app->params['city_url'] = $city->trans; }
/** * Finds the City model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return City the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = City::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionChangeCity($city) { $fCity = City::findOne($city); if ($fCity) { $this->city = \yii\helpers\Html::encode($fCity->name); Yii::$app->session->set('city', $this->city); Yii::$app->session->set('xy', $fCity->xy); Yii::$app->params['city_url'] = $fCity->trans; } return $this->goBack(); }
:</b> <?php echo $profile->gender ? 'Male' : 'Female'; ?> </p> <p><b><?php echo $profile->getAttributeLabel('country_id'); ?> :</b> <?php echo Country::findOne($profile->country_id)->name; ?> </p> <p><b><?php echo $profile->getAttributeLabel('city_id'); ?> :</b> <?php echo City::findOne($profile->city_id)->name; ?> </p> <p><b><?php echo $profile->getAttributeLabel('address'); ?> :</b> <?php echo $profile->address; ?> </p> <p><b><?php echo $profile->getAttributeLabel('timezone_id'); ?> :</b> <?php echo Timezone::findOne($profile->timezone_id)->name; ?>