mysql - Yii2: How to save different data in two tables from one form? -


public function actioncreate() {     $tim = new pstktim();     $user = new user();      if ($tim->load(yii::$app->request->post()) && $user->load(yii::$app->request->post())) {          $tim->id = yii::$app->generateid->getguid();         $tim->save();         $idtim = $tim->id;         $user->id = $tim->id;         $user->save();         return $this->redirect(['view', 'id' => $tim->id]);     } else {         return $this->render('create', [                     'tim' => $tim,                     'user' => $user,                          ]);     } } 

i trying insert different data in 2 different tables. table pstktim , user, how insert in user table in yii2.

could please try following way.

public function actioncreate() {     $tim = new pstktim();     $user = new user();      if ($tim->load(yii::$app->request->post())) {          $tim->id = yii::$app->generateid->getguid();         $tim->save();         $idtim = $tim->id;         if($user->load(yii::$app->request->post()))         {             $user->id = $tim->id;             $user->save(false);         }         return $this->redirect(['view', 'id' => $tim->id]);     } else {         return $this->render('create', [                     'tim' => $tim,                     'user' => $user,                          ]);     } } 

please let me know if require further information.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -