/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = City::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
protected function getCitiesView() { /** @var City[] $cities */ $cities = City::find()->all(); if (!$cities) { return []; } $result = []; foreach ($cities as $city) { $result[$city->id] = $city->name; } return $result; }
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; }
<?php use yii\web\View; use frontend\models\City; use yii\helpers\Html; /*карта*/ $this->registerJsFile('https://api-maps.yandex.ru/2.1/?lang=ru_RU'); if (!empty($accountModel->xy)) { $coord = $accountModel->xy; } else { $city = City::find()->where(['name' => $accountModel->city_name])->one(); $coord = $city->xy; } echo Html::tag('div', ' ', ['id' => "map"]); $jsData = "\n var coord = [ " . $coord . "];\n var descr = '" . $accountModel->username . "';\n var street_d = '" . $accountModel->address . "';\n var profileImg = '';\n "; if (!empty($accountModel->thumb)) { $jsData .= " profileImg = '<img style=\"width: 80px;border: 1px solid #CACACA;padding: 2px;\" src=\"" . $accountModel->thumb . "\" />';"; } $jsMap = <<<JS var myMap; // Дождёмся загрузки API и готовности DOM. ymaps.ready(init); function init () { var myMap, myPlacemark; myMap = new ymaps.Map('map', {
public function getCities() { return $this->hasMany(City::className(), ['id' => 'city_id'])->viaTable('country_city', ['country_id' => 'id']); }
/** * 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(); }
public function getCity() { return $this->hasOne(City::className(), ['id' => 'city_id']); }
public static function getCityList() { $citys = City::find()->all(); $citys = ArrayHelper::map($citys, 'id', 'name'); return $citys; }
:</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; ?>
/** * @inheritdoc */ public function beforeValidate() { if (!empty($this->city_name)) { $city = City::find()->where(['name' => $this->city_name])->one(); if (!empty($city)) { $this->city_id = $city->id; } } return parent::beforeValidate(); }
<p class="help-block"> <?php echo Module::t('views', 'Если вы уже зарегистрированы, выполните — {loginLink}', ['loginLink' => Html::a(Module::t('views', 'Вход'), [Module::URL_ROUTE_LOGIN])]); ?> </p> <?php $form = ActiveForm::begin(['id' => 'signupform', 'enableClientValidation' => true, 'validateOnSubmit' => true, 'validateOnBlur' => true]); ?> <fieldset> <?php $data = ArrayHelper::map(City::find()->orderBy('name')->all(), 'name', 'name'); echo $form->field($model, 'city_name')->widget(Select2::classname(), ['data' => $data, 'language' => 'ru', 'options' => ['placeholder' => 'Выберите город ...'], 'pluginOptions' => ['allowClear' => true, 'tags' => true, 'tokenSeparators' => [',', ' '], 'maximumInputLength' => 10]]); ?> <?php echo $form->field($model, 'username'); ?> <?php echo $form->field($model, 'phone')->textInput(['maxlength' => true, 'id' => 'phone', 'placeholder' => "+7 (___) ___-__-__"]); ?> <?php /*= $form->field($model, 'phone')->widget(MaskedInput::classname(), [ 'clientOptions' => [ 'name' => 'phone', 'mask' => '8(999)999-9999',
/** * @return \yii\db\ActiveQuery */ public function getCities() { return $this->hasMany(City::className(), ['region_id' => 'id'])->orderBy(['name' => SORT_ASC]); }
/** * @param $pid * @return array */ public function getCityList($pid) { $model = City::findAll(array('pid' => $pid)); return ArrayHelper::map($model, 'id', 'name'); }
use yii\helpers\Url; use yii\grid\GridView; use yii\bootstrap\Modal; use frontend\models\City; use frontend\models\Region; use yii\helpers\ArrayHelper; use kartik\select2\Select2; use yii\widgets\ActiveForm; use yii\widgets\MaskedInput; use yii\web\View; $regions = Region::find()->orderBy(['name' => SORT_ASC])->all(); $i = 0; $countInCol = ceil(count($regions) / 3); Modal::begin(['options' => ['id' => 'modal-city-content', 'tabindex' => false], 'toggleButton' => ['label' => $this->context->city . '<span class="caret"></span>', 'tag' => 'div', 'id' => 'modal-city'], 'header' => 'Выберите Ваш город']); echo '<div class="row" style="width:300px;margin: 0px auto 20px;">'; $Citys = City::find()->orderBy('name')->asArray()->all(); $dataCity = ArrayHelper::map($Citys, 'id', 'name'); $Citys = ArrayHelper::index($Citys, 'id'); $dataCity2 = ArrayHelper::map($Citys, 'trans', 'name'); echo Select2::widget(['name' => 'city_id', 'data' => $dataCity2, 'options' => ['placeholder' => 'Выберите город ..'], 'pluginOptions' => ['allowClear' => true]]); echo "</div>"; echo '<div class="row">'; echo "<div class='col-xs-4'>\n <ul>"; echo '<li> <a href="' . Url::toRoute(['/site/index', 'city_url' => $Citys['1']['trans']]) . '">' . $Citys['1']['name'] . '</a> </li> <li> <a href="' . Url::toRoute(['/site/index', 'city_url' => $Citys['2']['trans']]) . '">' . $Citys['2']['name'] . '</a> </li> <li> <a href="' . Url::toRoute(['/site/index', 'city_url' => $Citys['4']['trans']]) . '">' . $Citys['4']['name'] . '</a>