/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = GeobaseCity::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'tel', $this->tel]); return $dataProvider; }
public function actionGet_tel($cityid) { $model = new GeobaseCity(); if ($res = $model->findOne(['id' => $cityid])) { return $res->tel; } else { return 'fail'; } }
?> <div class="container-fluid"> <div class="row"> <nav role="navigation" class="navbar navbar-inverse"> <div class="container"> <div class="navbar-header header"> <div class="container"> <div class="row"> <div class="col-lg-12"> <div class="row"> <div class="col-md-6 col-sm-6 col-xs-12"> <img src="/img/azimut-logo.png" class="img-responsive pull-left" alt="Логотип"> </div> <div class="col-md-3 col-sm-3 col-xs-12"> <?php $city = \app\models\GeobaseCity::find()->orderBy(['name' => SORT_DESC])->asArray()->all(); ?> <div class="form-group city-form-group"> <select name="city" id="city" class="form-control"> <option value="" disabled >Выберите город</option> <option value="0" selected>Москва</option> <?php foreach ($city as $key => $value) { echo '<option value="' . $value['id'] . '">' . $value['name'] . '</option>'; } ?> </select> </div> <p class="header_tel ">+7(960)085-41-39</p> </div> <div class="col-md-3 col-sm-3 col-xs-12">
/** * Finds the GeobaseCity model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return GeobaseCity the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = GeobaseCity::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }