In controller- User model
public function actionCreate()
{
$model=new User;
// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
if($model->save())
{
$modelBuyer = new Buyer;
$modelBuyer->attributes = $_POST['Buyer'];
$modelBuyer->user_id= $model->user_id;
if ($modelBuyer->save())
$this->redirect(array('view','id'=>$model->user_id));
}
}
$this->render('create',array(
'model'=>$model,
));
}
.
.
.
Model Rules- User Model
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('first_name, lastname, email, password, country, hear_aboutus', 'required', ),
array('first_name,email','unique','message'=>'{attribute} already exist '),
array('first_name, lastname, email, password, country', 'length', 'max'=>25),
array('hear_aboutus', 'length', 'max'=>20),
array('email','email','checkMX'=>true),
array('password', 'compare', 'compareAttribute'=>'repeat_password'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('user_id, first_name, lastname, email, password, country, hear_aboutus', 'safe', 'on'=>'search'),
);
}
Model Rules- Buyer
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('user_id, industry, position', 'required'),
array('user_id', 'numerical', 'integerOnly'=>true),
array('industry, position', 'length', 'max'=>50),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('user_id, industry, position', 'safe', 'on'=>'search'),
);
}