Yii: Multimodelform Extension - How to create more than 1 member -
i'm using multimodelform extension create multiple model in single form. extension working great unfortunately more 1 member instead. have tried without success @ all.
my problem not make more 1 member extension.
here's code :
from controller
public function actioncreate() { yii::import('ext.multimodelform.multimodelform'); $model=new endheader; $member = new enddetail; $member2 = new enddetailnq; <-- ant new member. $validatedmembers = array(); //$validatedmembers2 = array(); // uncomment following line if ajax validation 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, )); }
from view
$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 form model 'tableview' => true, //if submitted not empty controller, //the form rendered validation errors 'validateditems' => $validatedmembers, //'sortattribute' => 'position', //array of member instances loaded 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 form model 'tableview' => true, //if submitted not empty controller, //the form rendered validation errors 'validateditems' => $validatedmembers, //'sortattribute' => 'position', //array of member instances loaded db 'data' => $member->findall('heh_id=:heh_id', array(':heh_id'=>$model->heh_id)), ));
Comments
Post a Comment