public function actionRegister()
{
$model=new RegisterForm;
// uncomment the following code to enable ajax-based validation
/*
if(isset($_POST['ajax']) && $_POST['ajax']==='register-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
*/
if(isset($_POST['RegisterForm']))
{
$model->attributes=$_POST['RegisterForm'];
if($model->validate())
{
// form inputs are valid, do something here
$profile=new Profiles;
$profile->id = "";
$profile->u_id = $model->id;
$profile->lastname = "";
$profile->firstname = "";
$profile->date_of_birth = "";
$profile->about = "";
if ($profile->validate()){
$model->save();
$profile->save(); //this does not save into db and return false
}
/* My hack method that works
$sql = 'INSERT INTO {{profiles}} (id,u_id,lastname,firstname,date_of_birth,about) VALUES ("",:u_id,"","","","")';
$parameters = array(":u_id"=>$model->id);
Yii::app()->db->createCommand($sql)->execute($parameters);
*/
$this->redirect(Yii::app()->homeUrl);
}
}
$this->render('register',array('model'=>$model));
}
u_id is a foreign key which references to the table user.id