Form With Multiple Models

Hi guys,

I have a problem with form with multiple models. My form looks like this:




<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(

	'id'=>'salon-update-form',

	'type'=>'vertical',

	'enableAjaxValidation'=>false,

)); ?>

<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'name'); ?>

		<?php echo $form->textField($model,'name',array('maxlength'=>70));?>

		<?php echo $form->error($model,'name'); ?>

	</div>

	

	<div class="row">

		<?php echo $form->labelEx($model,'address'); ?>

		<?php echo $form->textField($model,'address',array('size'=>45,'maxlength'=>70)); ?>

		<?php echo $form->error($model,'address'); ?>

	</div>

	

		<?php //echo $form->hiddenField($model,'lat'); ?>

		<?php //echo $form->hiddenField($model,'lng'); ?>

		

	<div class="row">

		<?php echo $form->labelEx($model,'description'); ?>

		<?php echo $form->textArea($model,'description',array('rows'=>6, 'cols'=>50)); ?>

		<?php echo $form->error($model,'description'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'phone'); ?>

		<?php echo $form->textField($model,'phone',array('size'=>45,'maxlength'=>45)); ?>

		<?php echo $form->error($model,'phone'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'website'); ?>

		<?php echo $form->textField($model,'website',array('size'=>45,'maxlength'=>45)); ?>

		<?php echo $form->error($model,'website'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'email'); ?>

		<?php echo $form->textField($model,'email',array('size'=>45,'maxlength'=>45)); ?>

		<?php echo $form->error($model,'email'); ?>

	</div>

	<p>Otevírací doba<p>

	<div class="row">

		<?php echo $form->textFieldRow($mon, 'open_time', array('class'=>'input-miniest', 'prepend'=>'Po', 'labelOptions'=> array('label'=>false)));?>

		-

		<?php echo $form->textField($mon, 'close_time', array('class'=>'input-miniest'));?>

	</div>

	

		<div class="row">

		<?php echo $form->textFieldRow($tue, 'open_time', array('class'=>'input-miniest', 'prepend'=>'Út', 'labelOptions'=> array('label'=>false)));?>

		-

		<?php echo $form->textField($tue, 'close_time', array('class'=>'input-miniest'));?>

	</div>

	

		<div class="row">

		<?php echo $form->textFieldRow($wen, 'open_time', array('class'=>'input-miniest', 'prepend'=>'St', 'labelOptions'=> array('label'=>false)));?>

		-

		<?php echo $form->textField($wen, 'close_time', array('class'=>'input-miniest'));?>

	</div>

	

		<div class="row"> 

		<?php echo $form->textFieldRow($thu, 'open_time', array('class'=>'input-miniest', 'prepend'=>'Čt', 'labelOptions'=> array('label'=>false)));?>

		-

		<?php echo $form->textField($thu, 'close_time', array('class'=>'input-miniest'));?>

	</div>

	

		<div class="row">

		<?php echo $form->textFieldRow($fri, 'open_time', array('class'=>'input-miniest', 'prepend'=>'Pá', 'labelOptions'=> array('label'=>false)));?>

		-

		<?php echo $form->textField($fri, 'close_time', array('class'=>'input-miniest'));?>

	</div>

	

		<div class="row">

		<?php echo $form->textFieldRow($sat, 'open_time', array('class'=>'input-miniest', 'prepend'=>'So', 'labelOptions'=> array('label'=>false)));?>

		-

		<?php echo $form->textField($sat, 'close_time', array('class'=>'input-miniest'));?>

	</div>

	

		<div class="row">

		<?php echo $form->textFieldRow($sun, 'open_time', array('class'=>'input-miniest', 'prepend'=>'Ne', 'labelOptions'=> array('label'=>false)));?>

		-

		<?php echo $form->textField($sun, 'close_time', array('class'=>'input-miniest'));?>

	</div>

	

	<div class="row buttons">

		<?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'Uložit')); ?>

	</div>


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



$model represents a shop and $mon-$sun represent opening hours in particular days.

Call from controller:




$openings = OpeningHours::model()->findAllByAttributes(array('salon_id'=> $model->id));

		$this->render('update',array(

			'model'=>$model,

			'mon'=>OpeningHours::getModelForDay($openings, OpeningHours::MON),

			'tue'=>OpeningHours::getModelForDay($openings, OpeningHours::TUE),

			'wen'=>OpeningHours::getModelForDay($openings, OpeningHours::WEN),

			'thu'=>OpeningHours::getModelForDay($openings, OpeningHours::THU),

			'fri'=>OpeningHours::getModelForDay($openings, OpeningHours::FRI),

			'sat'=>OpeningHours::getModelForDay($openings, OpeningHours::SAT),

			'sun'=>OpeningHours::getModelForDay($openings, OpeningHours::SUN),

		));



I have tried debugging and all models (there are 7 of them - $model, $mon - $sun representing days for opening hours) are available when form is displayed, which means they are passed correctly from controller to the form. Problem is, that once I submit the form, only $model and one of opening hours (I do not know which one thought) are passed by POST method to the controller. I need all of the models to be passed, does anyone know how to do that? I have followed this http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/ document, but there must be some problem…

Thanks for any help.

Please go through to this link , you will get a solution

http://www.yiiframework.com/wiki/19/

Well as you could read in my topic, that is exactly what I have done. With no effect thought. Thanks for reply anyway

http://www.yiiframework.com/doc/guide/1.1/en/form.table

this article solved my problem… just in case anyone would face the same:)