static function CompetitorOptions($position_id) { $competitors = ClassCommittee::model()->findByPk($position_id)->competitors; $results = array('0' => '请选择竞争者'); foreach ($competitors as $row) { $results[$row->competitor_id] = Student::model()->findByPk($row->competitor_id)->student_name; } return $results; }
/** * 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 ClassCommittee the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ClassCommittee::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionPositions() { $criteria = new CDbCriteria(); $criteria->select = 'position_id, position_name'; $criteria->addCondition('class_id=' . Yii::app()->user->class_id); $model = ClassCommittee::model()->findAll($criteria); foreach ($model as $i) { echo $i->position_name . '<br>'; foreach ($i->competitors as $j) { echo Student::model()->findByPk($j->competitor_id)->student_name; echo '      '; } echo '<br/>', '<hr/>'; } }
public function actionCommittee($position_id = -1) { if ($position_id == -1) { $criteria = new CDbCriteria(); $criteria->addCondition('class_id=' . Yii::app()->user->class_id); $model = ClassCommittee::model()->findAll($criteria); $this->render('committees', array('model' => $model)); } else { $model = ClassCommittee::model()->findByPk($position_id); $this->render('committee', array('model' => $model)); } }
static function positionOptions() { $criteria = new CDbCriteria(); $criteria->select = 'position_id, position_name'; $criteria->addCondition('class_id=' . Yii::app()->user->class_id); $model = ClassCommittee::model()->findAll($criteria); $postions = array('' => '请选择竞选岗位'); foreach ($model as $row) { $postions[$row->position_id] = $row->position_name; } return $postions; }