0

我正在使用Multimodelform扩展在一个表单中创建多个模型。此扩展程序运行良好,但不幸的是我想要超过 1 个成员。我已经尝试过了,但完全没有成功。

我的问题是我不能通过这个扩展获得超过 1 个成员。

这是我的代码:

从控制器

public function actionCreate()
        {
                Yii::import('ext.multimodelform.MultiModelForm');
                $model=new Endheader;
                $member = new Enddetail;
                $member2 = new Enddetailnq; <-- i just ant to this new member.

                $validatedMembers = array();
                //$validatedMembers2 = array();
                // Uncomment the following line if AJAX validation is needed
                 $this->performAjaxValidation($model);

                if(isset($_POST['Endheader']))
                {
                        $model->attributes=$_POST['Endheader'];
                   if(isset($_POST['sav'])){  
                        if((MultiModelForm::validate($member, $validatedMembers, $deleteItems) && MultiModelForm::validate($member2, $validatedMembers, $deleteItems)) && $model->save())
                        {
                                $masterValues = array('HEH_ID'=>$model->HEH_ID);
                                if(MultiModelForm::save($member,$validatedMembers,$deleteItems,$masterValues) && MultiModelForm::save($member2,$validatedMembers,$deleteItems,$masterValues))

                                    $msg2 = CHtml::link('View Details',array('view','id'=>$model->HEH_ID));
                                    //    $this->redirect(array('view','id'=>$model->HCO_ID));
                                Yii::app()->user->setFlash('success','You data have been saved successfully. '.$msg2);
                        $this->redirect(array('update','id'=>$model->HEH_ID));
                        }


                  }

                }

                $this->render('create',array(
                        'model'=>$model,'transport'=>$transport,
                    'member2'=>$member2,
                    'member'=>$member,
                   // 'validatedMembers2' => $validatedMembers2,
                    'validatedMembers' => $validatedMembers,
                ));
        }

从视图

$memberFormConfig = array(
      'elements'=>array(

       'HED_RPASS'=>array(
            'type'=>'text',
            'maxlength'=>11,
        ),

        'HED_PCS'=>array(
            'type'=>'text',
            'maxlength'=>5,
        ),  
    ));


$this->widget('ext.multimodelform.MultiModelForm',array(
        'id' => 'id_member', //the unique widget id
        'formConfig' => $memberFormConfig, //the form configuration array
        'model' => $member, //instance of the form model
         'tableView' => true,
        //if submitted not empty from the controller,
        //the form will be rendered with validation errors
        'validatedItems' => $validatedMembers,
        //'sortAttribute' => 'position',
        //array of member instances loaded from db
        'data' => $member->findAll('HEH_ID=:HEH_ID', array(':HEH_ID'=>$model->HEH_ID)),
    ));



$memberFormConfig2 = array(
      'elements'=>array(
       'HED_ARV_PCS'=>array(
            'type'=>'text',
            'maxlength'=>5,
        ),
         'HED_ARV_VOL'=>array(
            'type'=>'text',
            'maxlength'=>10,
        ),  
    ));


$this->widget('ext.multimodelform.MultiModelForm',array(
        'id' => 'id_member2', //the unique widget id
        'formConfig' => $memberFormConfig2, //the form configuration array
        'model' => $member2, //instance of the form model
         'tableView' => true,
        //if submitted not empty from the controller,
        //the form will be rendered with validation errors
        'validatedItems' => $validatedMembers,
        //'sortAttribute' => 'position',
        //array of member instances loaded from db
        'data' => $member->findAll('HEH_ID=:HEH_ID', array(':HEH_ID'=>$model->HEH_ID)),
    ));
4

0 回答 0