Yii Framework Forum: [ASK] Form Input dari Multiple Model - Yii Framework Forum

Jump to content

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

[ASK] Form Input dari Multiple Model Rate Topic: -----

#1 User is offline   yusronnube 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 30-November 10

Posted 21 December 2010 - 01:12 AM

Alo master, mau tanya tentang yii.

ane mau bikin form biodata dimana form itu ada aktivitas saat ini.
jenis aktivitas,keterangan aktivitas dan biodata merupakan model/table yang berbeda,

gimana ya, cara menyimpan aktivitas dalam mengisi satu form create?

ane udah nyoba pake cara ini
coding di biodatacontroller smentara di die buat ngetest.

        public function actionCreate()
        {
                $model=new Biodata;

               $model2=new AktifitasAlumni;

          
         
                if(isset($_POST['Biodata']) && isset($_POST['AktifitasAlumni']))
                {
                        $model->attributes=$_POST['Biodata'];
                        $model2->attributes=$_POST['AktifitasAlumni'];
                        die($model2->ket);
                        
                        foreach( $model2->idaktifitas as $xx)
                        {
                                $xxx = $xx;
                        }
                        die ($xxx);

   
                        $this->redirect(array('views','id'=>$model->idbiodata));
                }

                $this->render('add',array(
                        'model'=>$model,
                        'model2'=>$model2,
                ));

        }




di viewnya _form.php
        <tr>
                <td valign="top">
                        <?php echo $form->labelEx($model,'idaktifitas'); ?>
                </td>
                <td> : </td>
                <td>
                <?php
                        $aktivitas=Aktifitas::model()->findAll();
                        foreach ($aktivitas as $x)
                        {
                                echo $form->checkBox($model2,'idaktifitas');
                                echo $form->label($model2,$x->nama);
                                echo $form->textField($model2, 'ket');
                                echo '<br />';
//                              $x->nama;
                        }
                        //echo CHtml::activeCheckboxList($model2, 'idaktifitas', CHtml::listData($aktivitas, 'idaktifitas', 'nama'),array('template'=>'<p>{input}{label}</p>',));
                //      echo $form->textField($model2,'idaktifitas');
                        
 ?>

                        <?php echo $form->error($model2,'idaktifitas'); ?>
                </td>
        </tr>


help me ..
:)
0

#2 User is offline   ibiz4 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 26-November 10
  • Location:Indonesia

Posted 21 December 2010 - 08:49 PM

cek dulu yg ini gan, siapa tau berkenan
http://www.yiiframew...odel+form+input
WYSIWYG
(What Yii Serve is What You Get)
0

#3 User is offline   aqge 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 188
  • Joined: 02-September 10
  • Location:Indonesia

Posted 22 December 2010 - 01:58 AM

View Postibiz4, on 21 December 2010 - 08:49 PM, said:

cek dulu yg ini gan, siapa tau berkenan
http://www.yiiframew...odel+form+input



gan kayaknya banyak topic tentang ini sebelumnya, coba agan check dulu deh

http://www.yiiframew..._hl__cformmodel

http://www.yiiframew...ge__gopid__7151
Best Regard
Tidak ada coding yang salah
Yang ada hanyalah Coding yang lebih baik
0

#4 User is offline   yusronnube 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 30-November 10

Posted 10 January 2011 - 02:06 AM

View Postaqge, on 22 December 2010 - 01:58 AM, said:

gan kayaknya banyak topic tentang ini sebelumnya, coba agan check dulu deh

http://www.yiiframew..._hl__cformmodel

http://www.yiiframew...ge__gopid__7151


udah di coba gan caranya, tp malah muncul error gini
CDbException
Description

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`alumni2/al_aktifitas_alumni`, CONSTRAINT `fk_aktifitas_alumni_1` FOREIGN KEY (`idaktifitas`) REFERENCES `al_aktifitas` (`idaktifitas`) ON DELETE NO ACTION ON UPDATE CASCADE)
Source File

/var/www/html/yii/framework/db/CDbCommand.php(256)

00244: if($this->_connection->enableProfiling)
00245: Yii::endProfile('system.db.CDbCommand.execute('.$this->getText().')','system.db.CDbCommand.execute');
00246:
00247: return $n;
00248: }
00249: catch(Exception $e)
00250: {
00251: if($this->_connection->enableProfiling)
00252: Yii::endProfile('system.db.CDbCommand.execute('.$this->getText().')','system.db.CDbCommand.execute');
00253: Yii::log('Error in executing SQL: '.$this->getText().$par,CLogger::LEVEL_ERROR,'system.db.CDbCommand');
00254: $errorInfo = $e instanceof PDOException ? $e->errorInfo : null;
00255:
00256: throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',
00257: array('{error}'=>$e->getMessage())),(int)$e->getCode(),$errorInfo);
00258: }
00259: }
0

#5 User is offline   fastcrash 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 245
  • Joined: 10-March 10
  • Location:South Jakarta

Posted 10 January 2011 - 03:15 AM

Quote

ane mau bikin form biodata dimana form itu ada aktivitas saat ini.
jenis aktivitas,keterangan aktivitas dan biodata merupakan model/table yang berbeda,

gimana ya, cara menyimpan aktivitas dalam mengisi satu form create?

bisa gunakan extension AsmSelectex

hasil post nya nanti berupa array, tinggal di insert loop pake foreach
	protected function afterSave()
	{
		parent::afterSave();

		
	   if(empty($_POST['aktivitas']))
           {
	       $aktivitas = explode(",",$this->aktivitas);

                // if($this->isNewRecord == false)  //bisa cek create atau update
                foreach($aktivitas as $value){
					
		    $contact = new Biodata;
		    $contact->ID_Biodata=$this->ID_Biodata;
		    $contact->ID_Keterangan=$idOrganisasi;
		    $contact->save();
				
		}
            }
         }



kira2x seperti itu konsepnya, klo yg pake ajax bisa liat disini
CJuiDialog and AjaxSubmitButton
0

#6 User is offline   aqge 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 188
  • Joined: 02-September 10
  • Location:Indonesia

Posted 18 January 2011 - 05:27 AM

View Postyusronnube, on 10 January 2011 - 02:06 AM, said:

udah di coba gan caranya, tp malah muncul error gini
CDbException
Description

CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`alumni2/al_aktifitas_alumni`, CONSTRAINT `fk_aktifitas_alumni_1` FOREIGN KEY (`idaktifitas`) REFERENCES `al_aktifitas` (`idaktifitas`) ON DELETE NO ACTION ON UPDATE CASCADE)
Source File

/var/www/html/yii/framework/db/CDbCommand.php(256)

00244: if($this->_connection->enableProfiling)
00245: Yii::endProfile('system.db.CDbCommand.execute('.$this->getText().')','system.db.CDbCommand.execute');
00246:
00247: return $n;
00248: }
00249: catch(Exception $e)
00250: {
00251: if($this->_connection->enableProfiling)
00252: Yii::endProfile('system.db.CDbCommand.execute('.$this->getText().')','system.db.CDbCommand.execute');
00253: Yii::log('Error in executing SQL: '.$this->getText().$par,CLogger::LEVEL_ERROR,'system.db.CDbCommand');
00254: $errorInfo = $e instanceof PDOException ? $e->errorInfo : null;
00255:
00256: throw new CDbException(Yii::t('yii','CDbCommand failed to execute the SQL statement: {error}',
00257: array('{error}'=>$e->getMessage())),(int)$e->getCode(),$errorInfo);
00258: }
00259: }


kalo tablenya innoDB, ( atau foreign key constrain ) berarti agan harus menmperhatikan datamana dulu yang harus di inset, memperhatikan urut-urutan save modelnya,..
Best Regard
Tidak ada coding yang salah
Yang ada hanyalah Coding yang lebih baik
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