public function actionAdd($id) { if(isset($_GET['hid'])){ $pmodel = Housetype::model()->findByPk($_GET['hid']); }else{ $pmodel = new Housetype; } if(isset($_POST['Housetype'])) { if(empty($_POST['Housetype']['name'])){ Yii::app()->user->setFlash('error','房型名称必须填写!'); if($pmodel->isNewRecord){ $this->redirect(array('add','id'=>$id)); }else{ $this->redirect(array('add','id'=>$id,'hid'=>$_GET['hid'])); } }else{ $pmodel->tid = $id; $pmodel->name = $_POST['Housetype']['name']; $pmodel->aduit = $_POST['Housetype']['aduit']; $pmodel->child = $_POST['Housetype']['child']; $pmodel->aduit_price = $_POST['Housetype']['aduit_price']; $pmodel->chilend_price = $_POST['Housetype']['chilend_price']; $pmodel->description = $_POST['Housetype']['description']; if($pmodel->save(false)){ Yii::app()->user->setFlash('success','保存成功!'); $pmodel = new Housetype; }else{ Yii::app()->user->setFlash('error','保存失败,请重试!'); } } } //输出当前产品下的所有房型列表 $model = Housetype::model()->findAll(array('condition'=>"tid=$id")); $this->render('add',array( 'pmodel'=>$pmodel, 'model'=>$model, 'tid'=>$id, )); }