Using tabs, controller only recognizes me a model, how can I do it to recognize more than one model?

0

Good to everyone, with respect to my doubt is that I'm using tabs in a view but each tab goes to a different model, and therefore saved in their respective models, but at the time of doing the data save just step by post a single model and I do not get how the other recognizes me, I tried using mimodello-> validate (); but I also do not recognize the other model, I would also like to know if I can return from different ids at the time of the saved. Here I leave part of my code to see if you can help me

View

<?php
$form = $this->beginWidget('booster.widgets.TbActiveForm', array(
    'id' => 'registro_cobranza-form',
    'enableAjaxValidation' => false,
        ));
?>



<?php Yii::app()->clientScript->registerScript('validar2', '   

    $("#' . CHtml::activeId($estatus_cobranza, 'id_catalogo') . '").change(function(){
        var valor =$("#' . (Chtml::activeId($estatus_cobranza, "id_catalogo") ) . ' option:selected").val();

//alert(c);return false; este jquery es para la bandera que tengo en el controlador, ya que yo le doy a un select para que aparezcan las pestañas que necesito, son dos por cada tab, pero una siempre es la misma que es la de observaciones.

            if(valor=="2"){

                $("#paga").show();
                $("#c").hide();
                $("#Pagos_valor").val(valor);
            }else{

                $("#paga").hide();

            }
                if(valor=="3"){
                $("#Pagos_valor").val(valor);
                    $("#nopaga").show();
                     $("#c").hide();

                }else{
                    $("#nopaga").hide();

                } 




    });

'); ?>

<h3 align="center">Registro de cobranza</h3>

<div class="row">
    <div class="col-md-6 col-sm-12 col-xs-12">
        <?php echo $form->labelEx($estatus_cobranza, 'descripcion'); ?>
        <?php
        $this->widget(
                'booster.widgets.TbSelect2', array(
            'model' => $estatus_cobranza,
//            'name' => 'descripcion',
            'attribute' => 'id_catalogo',
            'data' => CatalogoCobranza::FindMaestrosByPadreSelect(1),
            'htmlOptions' => array(
                'style' => 'width: 100%',
                'placeholder' => '--Seleccione--',
                'multiple' => false,
            ),
        ));
        ?>    


    </div>
</div>

<br>
<?php echo $form->hiddenField($model, 'valor'); ?>
<div class="col-md-12 col-sm-12 col-xs-12" id="paga" style="display:none">

    <?php

    $this->widget('booster.widgets.TbTabs', array(
        'type' => 'pills',
        'justified' => true,
        'tabs' => array(
            array('active' => true, 'label' => 'Datos del pago',
                'content' => $this->renderPartial(
                        'pago_multa', array('id' => $id,
                    'montoMulta' => $montoMulta,
                    'model' => $model,
                    'multa_sugerida' => $multa_sugerida), true),
                'linkOptions' => array('id' => 'a')
            ),
            array('label' => 'Observaciones',
                'content' => $this->renderPartial('Observaciones', array('model' => $model, 'form' => $form,
                    'observaciones' => $observaciones,
                    'archivos' => $archivos), true),
                'linkOptions' => array('id' => 'c')
            ),
        ))
    );
    ?>


</div>

<div class="col-md-12 col-sm-12 col-xs-12" id="nopaga" style="display:none">


    <?php

    $this->widget('booster.widgets.TbTabs', array(
        'type' => 'pills',
        'justified' => true,
        'tabs' => array(
            array('active' => true, 'label' => 'Residente',
                'content' => $this->renderPartial('../residente/no_pago_multa', array('montoMulta' => $montoMulta,
                    'form' => $form,
                    'residente' => $residente,
                    'multa_sugerida' => $multa_sugerida,
                    'medidas_preventivas' => $medidas_preventivas), true),
                'linkOptions' => array('id' => 'b')
            ),
            array('label' => 'Observaciones',
                'content' => $this->renderPartial('Observaciones', array('form' => $form,
                    'observaciones' => $observaciones,
                    'archivos' => $archivos), true),
                'linkOptions' => array('id' => 'c')
            ),
        ))
    );
    ?>


</div>


<div class="row text-right">
    <div class="col-md-12 col-sm-12 col-xs-12">

<?php
$this->widget('booster.widgets.TbButton', array(
    'buttonType' => 'link',
//            'id' => 'blanqueo_formulario',
    'label' => 'Cancelar',
    'context' => 'danger',
//            'url' => $this->createUrl('vDistribucionProductorRubros/admin'),
    'htmlOptions' => array('class' => 'redirect'),
));
?> 

        <?php
        $this->widget('booster.widgets.TbButton', array(
            'buttonType' => 'submit',
            'id' => 'chequeo',
            'context' => 'success',
            'label' => 'Siguiente',
        ));
        ?> 



    </div>
</div>

</div>

<?php $this->endWidget(); ?> 

Controller

public function actionCreate($id = 1) { // ese $id=1 es solo en modo de prueba
$model = new Pagos;
$residente = new Residente;  
$multa_sugerida = new MultasSugeridas;
$estatus_cobranza = new CatalogoCobranza;
$medidas_preventivas = new MedidasPreventivas;

if (isset($_POST['Pagos'], $_POST['Residente'])) {
            $guardar = (int) $_POST['Pagos']['valor']; // este valor es una simple bandera que traigo de la vista.

 if ($guardar == 2) {

                $model->attributes = $_POST['Pagos'];
                $model->cantidad_dinero = (int) $_POST['Pagos']['cantidad_dinero'];
                $model->fk_modo_pago = $_POST['fk_modo_pago'];
                $model->fk_origen_pago = 15;
                $model->fk_estatus_pago = 2;
                $model->fk_banco = $_POST['fk_banco'];
                $model->cod_referencia = $_POST['Pagos']['cod_referencia'];
                $model->fecha_pago = Generico::formatoFecha($_POST['Pagos']['fecha_pago']);

              $model->id_usuario_creador = Yii::app()->user->id;
            } else if ($guardar == 3 ) {


                $residente->attributes = $_POST['Residente'];
                $multa_sugerida->attributes = $_POST['MultasSugeridas'];
                $medidas_preventivas->attributes = $_POST['MedidasPreventivas'];
                $multa_sugerida->unidad_tributaria = (int) $_POST['MultasSugeridas']['unidad_tributaria'];
                $residente->id_medida_preventiva = (int) $_POST['Residente']['fk_medida_preventiva_desc'];
                $model->fk_origen_pago = 15;
                $model->fk_estatus_pago = 3;
['id_archivo_adj'];
                $medidas_preventivas->medidas_preventivas = $_POST['MedidasPreventivas']['fk_medida_preventiva_desc'];
$residente->id_usuario_creador = Yii::app()->user->id;

            }
            if ($model->save()) // aca es donde pregunto lo de retornar los ids diferentes para la bdd, me imaginé algo como esto, pero no funcionó
                $this->redirect(array('view', 'id' => $model->id_pago));
            if ($residente->save()) {
                 $this->redirect(array('view', 'id' => $residente->id_residente));
            }
        }

Thank you very much everyone.

    
asked by Juan Romero 23.11.2016 в 15:04
source

1 answer

0

The tabs have to be inside a single tag form, there must also be a single submit for the whole form as in the following example so that the entries of all the models go in the same request to the server.

<Form>
 <div name="tab1"></div>
 <div name="tab2"></div>
 <div name="tab3"></div>
 <input type="submit"/>
</Form>
    
answered by 23.11.2016 в 15:35