how to add data from Employee table to user table in YII2 advanced -
i working on collage project i.e. employee management. have employee table in sql(crud generated gii). admin having rights create employee (there no signup).
my problem: when creating employee not able save data in user table also, please me save data in both employee , user table.
thanks in advance
update:
below code:
public function actioncreate() { $model1=new employee; $model2=new user; if(isset($_post['employee']) && isset($_post['user'])) { $model1->attributes=$_post['emoloyee']; $model2->attributes=$_post['user']; $model1->save(); $model2->save(); echo 'data saved in both tables'; } $this->render('create',array('model1'=>$model1,model2'=>$model2)); }
could have validation problem
try check way
...... $model1->attributes=$_post['emoloyee']; $model2->attributes=$_post['user']; if ($model1->validate() && $model2->validate() ) { $model1->save(); $model2->save(); } else { $errors1 = $model1->errors; $errors2 = $model2->errors; var_dump($errors1); var_dump($errors2); exit(); }
then debug try using
$model1->attributes=$_post['emoloyee']; $model2->attributes=$_post['user']; $model1->save(false); $model2->save(false);
and check in db if value saved ..
Comments
Post a Comment