static function campus_areaOptions() { $criteria = new CDbCriteria(); $criteria->select = 'area_id, area_name'; $model = CampusArea::model()->findAll(); $campus_areas = array('' => '请选择相应园区'); foreach ($model as $row) { $campus_areas[$row->area_id] = $row->area_name; } return $campus_areas; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return CampusArea the loaded model * @throws CHttpException */ public function loadModel($id) { $model = CampusArea::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionGetBuildings() { if (!isset($_POST['area_id'])) { return; } $area_id = $_POST['area_id']; $buildings = CampusArea::model()->findByPk($area_id)->buildings; $buildings = CHtml::listData($buildings, 'building_id', 'building_id'); $htmlData = CHtml::tag('option', array('selected' => 'selected', 'value' => ''), '请选择楼栋'); foreach ($buildings as $value => $key) { $htmlData .= Chtml::tag('option', array('value' => $value), Chtml::encode($key . '号')); } echo json_encode(array('htmlData' => $htmlData)); }