Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

How To Update Two Tables From One Form Yii

$
0
0
I have to update two tables from one form. I have two tables TestA and TestB. So how can I update two tables where TestB.testid=TestA.testid. Both the tables are populated. I need to update TestB based on the id of TestA. Below is the actionUpdate of TestA.

public function actionUpdate($id)
        {       $model_A=new TestA;    
                $model_B=new TestB;    
            $model=$this->loadModel($id);
            if(isset($_POST['TestA'])&&isset($_POST['TestB']))
            {
                 $model_A->attributes=$_POST['TestA'];                     
                 $model_B->attributes=$_POST['TestB'];

                 $model_B->name="test";                 

                 $model_A->save();
                 $model_B->save();    
            $this->render('update',array(
                'model'=>$model,
            ));
        } 


When I run the application, a new entry is created in TestB instead of updating the existing one. How can I pass the id to update the row in table TestB

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>