示例#1
0
 static function majorOptions()
 {
     $criteria = new CDbCriteria();
     $criteria->select = 'major_id, major_name';
     $model = Major::model()->findAll();
     return CHtml::ListData($model, 'major_id', 'major_name');
 }
 public function actionGetClasses()
 {
     if (!isset($_POST['major_id'])) {
         return;
     }
     $major_id = $_POST['major_id'];
     $classes = Major::model()->findByPk($major_id)->classes;
     $classes = CHtml::listData($classes, 'class_id', 'class_name');
     $htmlData = CHtml::tag('option', array('selected' => 'selected', 'value' => ''), '请选择班级');
     foreach ($classes as $value => $key) {
         $htmlData .= Chtml::tag('option', array('value' => $value), Chtml::encode($key));
     }
     echo json_encode(array('htmlData' => $htmlData));
 }
示例#3
0
 /**
  * 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 Major the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Major::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }