/** * 修改数据 */ public function actionUpdate($id) { if ($this->isPost) { $params = $this->request->post('City'); $res = $this->client->put('/city/{id}', $params, ['id' => $id]); if ($this->client->isValid || true) { return ''; } else { throw new UserError($this->client->errors); } } else { $res = $this->client->get('/city/{id}', ['id' => $id]); $model = new City(); $model->isNewRecord = false; $model->setAttributes($res, false); return $this->render('city_update', ['model' => $model]); } }
public function actionLists($id) { $countCitys = City::find()->where(['prov_id' => $id])->count(); $cities = City::find()->where(['prov_id' => $id])->all(); if ($countCitys > 0) { foreach ($cities as $city) { echo "<option value='" . $city->id . "'>" . $city->cityname . "</option>"; } } else { echo "<option> - </option>"; } }
/** * 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()) { // 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, 'Population' => $this->Population]); $query->andFilterWhere(['like', 'Name', $this->Name])->andFilterWhere(['like', 'CountryCode', $this->CountryCode])->andFilterWhere(['like', 'District', $this->District]); return $dataProvider; }
/** * 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()) { // 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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * 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()) { // 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, 'region_id' => $this->region_id, 'status' => $this->status]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'country_code', $this->country_code]); return $dataProvider; }
?> <?php echo $form->field($model, 'gender')->dropDownList(['女' => '女', '男' => '男']); ?> </div> <div class="form-inline"> <?php echo $form->field($model, 'prov')->dropDownList(ArrayHelper::map(Prov::find()->all(), 'id', 'provname'), ['prompt' => '选个省直/辖市', 'onchange' => ' $.post( "index.php?r=maker/lists&id=' . '"+$(this).val(), function( data ) { $( "select#maker-city" ).html( data ); });']); ?> <?php echo $form->field($model, 'city')->dropDownList(ArrayHelper::map(City::find()->all(), 'id', 'cityname'), []); ?> </div> <?php echo $form->field($model, 'begoodat')->checkboxlist(ArrayHelper::map(Begoodatprof::find()->all(), 'id', 'begoodat'), [0, 2]); ?> <?php echo $form->field($model, 'unicres')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'simpcv')->textarea(['maxlength' => true]);
public function trans_city($id) { $city = City::find()->where('id =' . $id)->one(); return $city->cityname; }
/** * @return \yii\db\ActiveQuery */ public function getCity() { return $this->hasOne(City::className(), ['id' => 'city_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.'); } }
/** * @return \yii\db\ActiveQuery */ public function getCities() { return $this->hasMany(City::className(), ['prov_id' => 'id']); }