select = 'is_private'; $criteria->addCondition("school_id={$schoolId}"); $result = $this->find($criteria); if ($result){ return $result->is_private; }else{ return 0; } } public function savePrivate($schoolId, $isPrivate) { $criteria = new CDbCriteria(); $criteria->select = 'id'; $criteria->addCondition("school_id={$schoolId}"); $result = $this->find($criteria); if ($result){ //更新 $bool = $this->updateByPk($result->id,array('is_private'=>$isPrivate)); if($bool!==false){ return true; }else{ return false; } }else{ $sp = new BSchoolPrivate(); $sp->is_private = $isPrivate; $sp->school_id = $schoolId; $bool = $sp->save(); if($bool){ return true; }else{ return false; } } } }