1

Please i need a big help here. AM developing a yii application where i have to loop through my form and do a batch insert. I found bacth update in yii but ive not been able to see how to do batch insert and validation. Please help.

Here is my View:

<?php for($i=0;$i< $this->getDisplayArchModel();$i++) {?>
     <FIELDSET class="radios">
          <div class="row">
            <?php echo $form->labelEx($model,'competency_type'); ?>
    <?php echo $form->textField($model,'competency_type'); ?>
    <?php echo $form->error($model,'competency_type'); ?>
          </div>

         <div class="row">
    <?php echo $form->labelEx($model,'definition'); ?>
    <?php echo $form->textArea($model,'definition'); ?>
    <?php echo $form->error($model,'definition'); ?>
</div> 

          </fieldset>
       <?php } ?>

Controller ::

public function actionDisplayArchModel()
    {

        $validateCat = $this->getDisplayArchModel();
        if($validateCat == NULL)
        $this->redirect(array('architecture'));

        $model = new CompetencyType;
        if(isset($_POST['CompetencyType']))
        {
            $model->attributes = $_POST['CompetencyType']; 
            if($model->validate()){
                foreach($_POST['CompetencyType'] as $value)
                {
                    echo $value;
                }

            }
        }
       $this->render('displayArchModel' ,array('model'=>$model));

    }
spatanx
  • 49
  • 1
  • 7

1 Answers1

0

Sometimes we want to collect user input in a batch mode. That is, the user can enter the information for multiple model instances and submit them all at once. We call this tabular input because the input fields are often presented in an HTML table.

To work with tabular input, we first need to create or populate an array of model instances, depending on whether we are inserting or updating the data. We then retrieve the user input data from the $_POST variable and assign it to each model. A slight difference from single model input is that we retrieve the input data using $_POST['ModelClass'][$i] instead of $_POST['ModelClass'].

more on collecting Tabular Input

Pentium10
  • 204,586
  • 122
  • 423
  • 502