Yii:Multimodelform Extension - 如何创建多个成员

时间:2013-08-20 03:10:39

标签: yii yii-extensions multi-model-forms

我正在使用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)),
    ));

0 个答案:

没有答案