Moving whole row between two tables <p>I have to tables with identical structure, client_data, new_client_data. Now I want to move whole one row from one table to another. I've found a way to do it, it`s working fine, but I'm wondering if there is more elegant and clean way to do it.</p> <p>new_client_data / controller:</p> <pre><code>public function actionPromotion($id) + { + $model = $this-&gt;findModel($id); + + $clientData = new ClientData; + $newClientNumber = $clientData-&gt;setNewClientNumber(); + + $clientContacts = new OClientContacts; + + + if ($model-&gt;load(Yii::$app-&gt;request-&gt;post())) { + if($this-&gt;moveToClients(Yii::$app-&gt;request-&gt;post(), $model-&gt;id) &amp; $clientContacts-&gt;moveContacts($id)){ + return $this-&gt;redirect(['index']); + } else { + return $this-&gt;render('promprep', [ + 'model' =&gt; $model, + 'newClientNumber' =&gt; $newClientNumber, + ]); + } + } else { + return $this-&gt;render('promprep', [ + 'model' =&gt; $model, + 'newClientNumber' =&gt; $newClientNumber, + ]); + } + } </code></pre> <p>It's basic controller method build from standard actionUpdate. If user will submit all post data correctly then function is passing all post data to another method in that controller. ( also i`m wondering if shouldn't place in model instead).</p> <pre><code>+ public function moveToClients($post, $id){ + $ClientData = new ClientData; + + $ClientData-&gt;name = $post['OClientData']['name']; + $ClientData-&gt;clientNumber = $post['OClientData']['clientNumber']; + $ClientData-&gt;abr= $post['OClientData']['abr']; + $ClientData-&gt;adress = $post['OClientData']['adress']; + $ClientData-&gt;city = $post['OClientData']['city']; + $ClientData-&gt;postal = $post['OClientData']['postal']; + $ClientData-&gt;phone = $post['OClientData']['phone']; + $ClientData-&gt;fax = $post['OClientData']['fax']; + $ClientData-&gt;email = $post['OClientData']['email']; + $ClientData-&gt;nip = $post['OClientData']['nip']; + $ClientData-&gt;krs = $post['OClientData']['krs']; + $ClientData-&gt;regon = $post['OClientData']['regon']; + $ClientData-&gt;www = $post['OClientData']['www']; + $ClientData-&gt;description = $post['OClientData']['description']; + $ClientData-&gt;isNewRecord = true; + $ClientData-&gt;id = null; + + if($ClientData-&gt;save()){ + $this-&gt;actionDelete($id); + return true; + } + return false; + + } </code></pre> <p>My question is: "Is there a way to do this in more elegant way?";</p> <p>Edit. Question: "Should this <code>moveToClients</code> method land in the controller?";</p>