/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new Personaddress; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if(isset($_POST['Personaddress'])) { $model->attributes=$_POST['Personaddress']; if($model->save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('create',array( 'model'=>$model, )); }
public function saveOrUpdatePersonAddress($model, $addrtype = null) { $rtn = true; $paramarray = array( 'person_id'=> $model->id, 'location_id'=> $model->address->id, ); if(!empty($addrtype)) { $paramarray['type'] = $addrtype; } $records = Personaddress::model()->findAllByAttributes($paramarray); $found = count($records) > 0; if($found) { $record = $records[0]; } else { $record = new Personaddress; } $record->type = $model->addresstype; $record->person_id = $model->id; $record->location_id = $model->address->id; $rtn = $record->save(); $model->address = $record; return $rtn; }