static function categoryOptions() { $criteria = new CDbCriteria(); $criteria->select = 'tucao_cate_id, tucao_cate_name'; $model = TucaoCategory::model()->findAll(); $cates = array('' => '请选择吐槽类型'); foreach ($model as $row) { $cates[$row->tucao_cate_id] = $row->tucao_cate_name; } return $cates; }
/** * 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 TucaoCategory the loaded model * @throws CHttpException */ public function loadModel($id) { $model = TucaoCategory::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionTucao($cate_id = -1, $self = false) { // 全部吐槽分类 // 自己来吐槽 if ($self == true) { $_GET['cateI_id'] = $cate_id; $model = new Tucao(); if (isset($_POST['Tucao'])) { $model->attributes = $_POST['Tucao']; $model->save() or die('发布失败'); $this->redirect(array('index/tucao')); } $this->render('createTucao', array('model' => $model)); } else { if ($cate_id == -1) { $criteria = new CDbCriteria(); $criteria->addCondition('class_id=' . Yii::app()->user->class_id); $model = TucaoCategory::model()->findAll($criteria); $this->render('tucaoCategory', array('model' => $model)); } else { $_GET['cate_id'] = $cate_id; $_GET['cate_name'] = TucaoCategory::model()->findByPk($cate_id)->tucao_cate_name; $criteria = new CDbCriteria(); $criteria->addCondition('tucao_cate_id=' . $cate_id); $criteria->limit = 10; $model = Tucao::model()->findAll($criteria); $this->render('tucaos', array('model' => $model)); } } }