I want to update 2 models(contact,cand) in one action of a controller for third model(user) . the code is as follows
public function actionProfile($type)
{
$model=new contact;
$userid=Yii::app()->user->id;
$curr_date=date('d/m/Y');
$timestamp=CDateTimeParser::parse($curr_date,'dd/MM/yyyy');
if(isset($_POST['experience']))
{
$cand_id= Yii::app()->db->createCommand('select id from cand where user_id=:uid')->bindValue('uid',$userid)->queryRow();
$candmodel=cand::model()->findByPk((int)$cand_id);
$candmodel->experience=$_POST['experience'];
$candmodel->current_location=$_POST['location'];
$candmodel->current_salary=$_POST['salary'];
if($candmodel->save()){
echo "CAND SAVED";
} else{
echo "CAND MODEL NOT SAVED";
}
}
if(isset($_POST['contact']))
{
$model->attributes=$_POST['contact'];
$model->deleted='N';
$model->created=$timestamp;
$model->updated=$timestamp;
$model->createdby=$userid;
$model->updatedby=$userid;
if($model->save()){
echo "SAVED";
exit;
}
}
$this->render('profile_pinfo',array(
'model'=>$model,
));
}
The contact model gets updated successfully but the cand model does not get update . the else block " echo "CAND MODEL NOT SAVED"; " is running always , can anyone help me out
Now I am able to load the model. if I print the model it gives me the complete record along with the latest value of the properties I am updating . But still the model does not get updated. can please give me some idea.
Hi softark,
I got it solved , I was rendering model partially , some rules were getting violated, thats why the model was not getting updated , thanks once again