public function cities($params = array()) { $cache = Yii::app()->cache; if ($city_all = $cache->hget('city', 'cities')) { $provices = CJSON::decode($city_all); } else { //获取全国省列表 $provice_obj = YhmCity::model()->findAll('class_parent_id=:id', array(':id' => '1')); $provices = array(); if ($provice_obj) { foreach ($provice_obj as $key => $val) { $provices[$val->class_id] = array('id' => $val->class_id, 'name' => $val->class_name); } } $obj = YhmCity::model()->findAll('class_parent_id >:id and class_type = :type', array(':id' => 1, ':type' => 2)); if ($obj) { foreach ($obj as $key => $val) { if ($val->class_parent_id > 1) { } $provices[$val->class_parent_id]['cites'][] = array('id' => $val->class_id, 'name' => $val->class_name); } $cache->hset('city', 'cities', json_encode($provices, JSON_UNESCAPED_UNICODE)); } } $result = array('cities' => $provices); return $this->notice('OK', 0, '成功', $result); }
public function actionCity() { if (isset($_POST) && isset($_POST['code'])) { $code = $_POST['code']; if ($code) { $city_obj = YhmCity::model()->findAll('class_parent_id=:id', array(':id' => $code)); if ($city_obj) { foreach ($city_obj as $key => $val) { echo CHtml::tag('option', array('value' => $val->class_id), CHtml::encode($val->class_name), true); } } } } }
public function actionUpdate() { $id = Yii::app()->request->getParam('id'); if (intval($id)) { $model = User::model()->findByPk($id); if ($_POST['User']) { $userinfo = $_POST['User']; if ($userinfo['password'] && $userinfo['nickname']) { $userinfo['password'] = md5($userinfo['naickname'] . md5($userinfo['password'])); } else { unset($userinfo['password']); } if (!$userinfo['province']) { unset($userinfo['province']); } if (!$userinfo['city']) { unset($userinfo['city']); } $model->attributes = $userinfo; //if (ExaminationUserInfo::model()->updateByPk($id,$userinfo)) { if ($model->validate() && $model->save()) { Yii::app()->user->setFlash('setStaff', '修改成功'); $this->redirect(array('user/index')); } } if ($model) { $model->setAttribute('password', ''); } else { $model = new User("create"); } $province = YhmCity::model()->province(); $this->render('update', ['model' => $model, 'province' => $province]); } else { $this->redirect(array('user/index')); } }
public function province() { $province = array(); $pro_obj = YhmCity::model()->findAll('class_type=:type', array(':type' => 1)); if ($pro_obj) { foreach ($pro_obj as $key => $val) { $province[$val->class_id] = $val->class_name; } } return $province; }
<?php echo $form->dropDownList($model, 'province', $province, ['class' => 'select2 select-simple', 'empty' => '请选择省市', 'ajax' => ['url' => Yii::app()->createUrl('/api/city'), 'data' => array('code' => 'js:$(this).val()'), 'type' => 'post', 'success' => 'js:function(html){$("#city").empty();$("#city").html(html)}']]); ?> </div > <?php echo $form->error($model, 'province'); ?> </div> <div class="form-group"> <?php echo $form->label($model, 'city', ['class' => 'col-sm-4 control-label']); ?> <div class="col-sm-2" > <?php echo $form->dropDownList($model, 'city', $model->province ? YhmCity::model()->city($model->province) : [], ['class' => 'select2 slect-simple', 'id' => 'city', 'empty' => '请依次选择省市']); ?> </div > <?php echo $form->error($model, 'city'); ?> </div> <div class="form-group" > <div class="col-sm-offset-5" > <div class="col-sm-3"> <button class="btn btn-primary debts-info-submit submitBtn" type="submit" ><?php echo "确认"; ?> </button >