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

Load Reccords On Update From 2 Models On Same _Form

$
0
0
Hello everybody thanks for reading.
I have a little issue .
I have _form.php file that i use to collect data that is saved in 2 different tables. Plz Reffer below for example.
On the update page however only the records from one table get loaded.
I wanted to know how can i load the reccords from the other table on the update page.
Controler Update Function :
public function actionUpdate($id) {
        $model = $this->loadModel($id);

        if (isset($_POST['UserRegistry'])) {
            //THIS SAVES THE USER ON THE USER TABLE
            $user = new User;
            $user->user_name = $_POST['UserRegistry']['user_name'];
            $user->password = $_POST['UserRegistry']['password'];
            $user->role = $_POST['UserRegistry']['role'];
            $user->save(false);
           
            $model->attributes = $_POST['UserRegistry'];
            $model->id_user = $user->id_user;
            if ($model->save())

            //SAVE THE USERS TO THE CHOSEN GROUP
                $groups = $_POST['UserRegistry']['groups'];
            if (!empty($groups)) {

                foreach ($groups as $group) {
                    $bridge = new BridgeGroup();
                    $bridge->id_user_registry = $model->id_user_registry;
                    $bridge->id_group = $group;
                    $bridge->save(false);
                }
            }


            $this->redirect(array('view', 'id' => $model->id_user_registry));
        }

On the model =
public $user_name;
public $password;
public $role;
On the _form.php
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'user-registry-form',
	'enableAjaxValidation'=>true,
)); 

?>

	<?php echo $form->errorSummary($model); ?>

       
        
                <?php 
//THIS IS INSERTED ON THE CURRENT TABLE
echo $form->textFieldRow($model,'firstname',array(
                    'class'=>'span10',
                    'maxlength'=>45,
                    'hint'=>__('The First Name of the participant.'),
                    'prepend'=>'<i class="icon-text-width"></i>',
                    )); ?>

               
     
         <?php 
//THIS IS INSERTED INTO THE USER TABLE
echo $form->textFieldRow($model,'user_name',array(
                'class'=>'span10',
                'hint'=>__('Login username of the contact being inserted'),
                'prepend'=>'<i class="icon-user"></i>',
                'maxlength'=>45,
                'autocomplete'=>'off'
                )); ?>
     </div>
      ...........


When i update this i only get the first name loaded and the user_name dose not load. Any help or tips will help me a lot. Thanks in advanced

Viewing all articles
Browse latest Browse all 18717

Trending Articles



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