public function actionAnnounce($cate_id = -1, $announce_id = -1) { // 所有类型的公告和最新的10 条公告 if ($cate_id == -1) { // 取出所有公告分类 $criteria = new CDbCriteria(); $criteria->addCondition('class_id=' . Yii::app()->user->class_id); $model = AnnounceCategory::model()->findAll($criteria); // 取出前若干条最新公告 $criteria = new CDbCriteria(); $criteria->order = 'level desc, start_time desc'; $criteria->limit = 10; $criteria->addCondition('class_id=' . Yii::app()->user->class_id); $lastest_announces = ClassAnnounce::model()->findAll($criteria); // echo count($lastest_announces);die; $this->render('announce_cates', array('announce_cates' => $model, 'lastest_announces' => $lastest_announces)); } else { if ($announce_id == -1) { $_GET['cate_id'] = $cate_id; $_GET['cate_name'] = AnnounceCategory::model()->findByPk($cate_id)->cate_name; $criteria = new CDbCriteria(); $criteria->order = 'level desc, start_time desc'; $criteria->limit = 10; $criteria->addCondition('class_id=' . Yii::app()->user->class_id); if ($cate_id != -1) { $criteria->addCondition('cate_id=' . $cate_id); } $model = ClassAnnounce::model()->findAll($criteria); $this->render('announces', array('model' => $model)); } else { $criteria = new CDbCriteria(); $criteria->addCondition('announce_id=' . $announce_id); $model = ClassAnnounce::model()->find($criteria); $this->render('announce_view', array('model' => $model)); } } }
/** * 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 ClassAnnounce the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ClassAnnounce::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }