Hello!
I have a form with a table "table1" and another form with "table2". I need to present both forms in a page at same time. I do this using renderPartial in the '_form' or 'create' view from table1 but when I press save button in form "table1" something strange occurs in the insert process. Seems like the insert clause are executed repeatedly, four to six times. Here's my code:
How to make this functions correctly?
I have a form with a table "table1" and another form with "table2". I need to present both forms in a page at same time. I do this using renderPartial in the '_form' or 'create' view from table1 but when I press save button in form "table1" something strange occurs in the insert process. Seems like the insert clause are executed repeatedly, four to six times. Here's my code:
Quote
create.php view from table strain (table1) with a renderPartial to the _form from table strainFacts
<?php /* @var $this StrainController */ /* @var $model Strain */ $this->breadcrumbs=array( 'Strains'=>array('index'), 'Cadastrar', ); $this->menu=array( array('label'=>'Listar Strains', 'url'=>array('index')), array('label'=>'Gerenciar Strains', 'url'=>array('admin')), ); ?> <h1>Create Strain</h1> <?php echo $this->renderPartial('_form', array('model'=>$model)); ?> <?php echo $this->renderPartial('/strainFacts/_form', array('model'=>$strainFacts)); ?>
Quote
StrainController.php
public function actionCreate() { $model=new Strain; $strainFacts=$this->newStrainFacts($model); if(isset($_POST['Strain'])) { $model->attributes=$_POST['Strain']; $model->cd_strain_facts_id = $strainFacts->cd_strain_facts_id; if($model->save()) $this->redirect(array('view','id'=>$model->cd_strain_id)); } $this->render('create',array( 'model'=>$model, 'strainFacts'=>$strainFacts )); } public function newStrainFacts() { $strainFacts=new StrainFacts; if(isset($_POST['StrainFacts'])) { $strainFacts->attributes = $_POST['StrainFacts']; $strainFacts->save(); } return $strainFacts; }
How to make this functions correctly?