title: Yii2: How to save different data in two tables from one form?
body: <pre><code>public function actionCreate() {
      $tim = new PstkTim();
      $user = new User();
  
      if ($tim-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $user-&gt;load(Yii::$app-&gt;request-&gt;post())) {
  
          $tim-&gt;id = Yii::$app-&gt;generateid-&gt;getGUID();
          $tim-&gt;save();
          $idTim = $tim-&gt;id;
          $user-&gt;id = $tim-&gt;id;
          $user-&gt;save();
          return $this-&gt;redirect(['view', 'id' =&gt; $tim-&gt;id]);
      } else {
          return $this-&gt;render('create', [
                      'tim' =&gt; $tim,
                      'user' =&gt; $user,                 
          ]);
      }
  }
  </code></pre>
  
  <p>I am Trying to insert different data in two different tables. Table PstkTim and User, how do I insert in to User table in Yii2.</p>