Yii Framework Forum: Multiple Insert To Model - Yii Framework Forum

Jump to content

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

Multiple Insert To Model Rate Topic: -----

#1 User is offline   almousawy87 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 16-January 12

Posted 17 May 2014 - 02:19 AM

Hello everyone, I need your help.
I need to insert 2 records in the same time to table therefore I made my _form.php as the following:
	<div id="hor">
		<?php echo $form->labelEx($modell[0],'[0]fromplace'); ?>
		<?php echo $form->textField($modell[0],'[0]fromplace',array('size'=>20,'maxlength'=>40)); ?>
		<?php echo $form->error($modell[0],'[0]fromplace'); ?>
        </div>
	<div id="hor">
        
		<?php echo $form->labelEx($modell[1],'[1]fromplace'); ?>
		<?php echo $form->textField($modell[1],'[1]fromplace',array('size'=>20,'maxlength'=>40)); ?>
		<?php echo $form->error($modell[1],'[1]fromplace'); ?>
        </div>


In Create I do the following:
               if(isset($_POST['Extra'][0]))
                        {
                              $model2->attributes=$_POST['Extra'][0];
                              $model2->extraid=$model->id;
                              $model2->save();
        
                        }
                   if(isset($_POST['Extra'][1]))
                        {
                              $model2a->attributes=$_POST['Extra'][1];
                              $model2a->extraid=$model->id;
                             $model2a->save();
        
                        }


sometimes I leave one of the field empty so I added to beforesave()
 public function beforeSave()
        {
                if(parent::beforeSave())
                {
                        if ($this->fromplace=="")
                                return false;
                   
                }
        return true;
        }


the create action is working properly but the problem with update because of one of the field is not filled so the update page is not loaded properly.
how can I solve this issue.
0

#2 User is offline   ahb360 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 15-February 10

Posted 17 May 2014 - 02:34 AM

I think the you can find the answer to your question here

http://www.yiiframew...1/en/form.table
0

Share this topic:


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

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