Yii Framework Forum: 2 model dalam 1 form - Yii Framework Forum

Jump to content

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

2 model dalam 1 form Rate Topic: -----

#1 User is offline   kecil_RI 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 23-February 12

Posted 02 June 2012 - 03:48 AM

saya punya 2 model Pengirim dan Penerima
primary key Pengirim(id_pengirim) dan penerima(id_penerima)
saya jadiin pengirim buat jadi model input 2 model ini

PengirimController saya
public function actionCreate()
{
$model=new Pengirim;
$modelPenerima=new Penerima;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['Pengirim']))
{
$model->attributes=$_POST['Pengirim'];
$modelPenerima->attributes=$_POST['Penerima'];

$valid=$model->validate();
$valid=$modelPenerima->validate() && $valid;

if($valid)
{
if($model->save(false))
{
$modelPenerima->id_penerima = $model->id_pengirim;
$modelPenerima->save(false);
$this->redirect(array('view','id'=>$model->pengirim));
}
}
}

$this->render('create',array(
'model'=>$model,
'modelPenerima'=>$modelPenerima,
));
}

salah dan keluar
CException

Property "Pengirim.pengirim" is not defined.

tolong bantu
0

#2 User is offline   junxiong 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 541
  • Joined: 21-June 10

Posted 03 June 2012 - 08:36 AM

Saya kurang tahu tujuan agan untuk apa, tapi agan menulis code ini:
$this->redirect(array('view','id'=>$model->pengirim));

tebakan ane, mungkin maksud agan
$this->redirect(array('view','id'=>$model->pengirim_id));
“The most likely way for the world to be destroyed, most experts argue, is by accident. That’s where we come in; we’re computer professionals. We cause accidents.” - Nathaniel Borenstein

Yii Playground : Collaborative demo apps. You can join to improve it too!
My Team's Blog: In Indonesian.
0

#3 User is offline   J.J 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 126
  • Joined: 01-April 11

Posted 04 June 2012 - 02:22 AM

Wah sudah ada master nya disini.. Saya jamin pasti solved masalahnya.. ;D. Mohon petunjuknya masta.. :)
0

#4 User is offline   kecil_RI 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 23-February 12

Posted 04 June 2012 - 10:20 PM

thanks gan dah bisa.. arigato
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