Yii Framework Forum: Collect In $_Post Many Models Info For The Same Key/columns - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Collect In $_Post Many Models Info For The Same Key/columns Rate Topic: -----

#1 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 18 January 2013 - 05:26 AM

HI all,

Here is the problematic situation : In a form, in order to update a record, I use three different models from another table. But these models are all from the same table.

So when I submit my form, in my $_POST I have only one model info in the POST array corresponding to the table instead of 3... Submittion takes only the last record edit in form. Indeed I edit the same key name for the models...

I don't really know how to collect the multiple model info which corresponds to the same key but for different models.
0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 573
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 18 January 2013 - 05:36 AM

Can you share the code?
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#3 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 18 January 2013 - 05:38 AM

Well, a solution should be to create public variables in the table activeRecord of my 3 models then edit and hand out the variables to the 3 models before to save them...

But sounds very dirty =(
0

#4 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 18 January 2013 - 05:53 AM

Controller edit action starts with :

    $model=$this->loadModel($id);
    $mod_level_1 = ModLevel::model()->findByAttributes(array('mod_id'=>$model->id,'out_id'=>'3'));
    $mod_level_2 = ModLevel::model()->findByAttributes(array('mod_id'=>$model->id,'out_id'=>'1'));
    $mod_level_3 = ModLevel::model()->findByAttributes(array('mod_id'=>$model->id,'out_id'=>'2'));

...

    $this->render('/Mod/update',array('model'=>$model,
                                             'mod_level_1'=>$mod_level_1,
                                             'mod_level_2'=>$mod_level_2,
                                             'mod_level_3'=>$mod_level_3));
  }



then in form :
<div class="row" disabled="disabled">
		<?php echo $form->labelEx($model,'name'); ?>
		<?php echo  $form->textField($model,'name',array('rows'=>1, 'cols'=>50));?>
	</div>
  
  <div class="row">
		<?php echo $form->labelEx($mod_level_1,'level'); ?>
    <?php echo $form->dropDownList($mod_level_1,'level',
    array('1','2','3','4')); ?>
	</div>
  
  <div class="row">
		<?php echo $form->labelEx($mod_level_3,'level'); ?>
    <?php echo $form->dropDownList($mod_level_3,'level',
    array('1','2','3','4')); ?>
	</div>
  
  	<div class="row">
		<?php echo $form->labelEx($mod_level_2,'level'); ?>
    <?php echo $form->dropDownList($mod_level_2,'level',
    array('1','2','3','4')); ?>
	</div>


With that... I would have in $_POST only the value for mod_level_2
0

#5 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 573
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 19 January 2013 - 10:51 PM

It is because that in each of your dropdown list the name of filed is level.

Try it with as
    <?php echo $form->dropDownList($mod_level_2,'level[]',
    array('1','2','3','4')); ?>


Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#6 User is offline   Zugluk 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 205
  • Joined: 08-August 12

Posted 21 January 2013 - 05:39 AM

View PostPeRoChAk, on 19 January 2013 - 10:51 PM, said:

It is because that in each of your dropdown list the name of filed is level.

Try it with as
    <?php echo $form->dropDownList($mod_level_2,'level[]',
    array('1','2','3','4')); ?>




It works =) Thanks for reply ;)

I didn't know I could use something else than table attributes type and name for form inputs.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users