Form Data To Two Tables

Hi, I am new member. I want to add form data to two tables. The main data is ‘nasabah’ (english: client), and ‘rekening’ for other data (english: bank account).

I create it with Gii. The code I added was bolded.


	public function actionCreate()


		$model=new Nasabah;

		[b]$rekening = new Rekening;[/b]

		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);













<h1>Create New Nasabah</h1>

<?php echo $this->renderPartial('_form_create', array('model'=>$model)); ?>

Originally it’s use _form, but I create _form_create, because for edit: nasabah and rekening at their individuals form.


<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

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

	<div class="row">

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

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

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


	<div class="row">

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

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

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


<!-- other data //-->

<!-- Rekening data start //-->

<h1>Data Rekening</h1>

	<div class="row">

		<?php echo $form->labelEx($rekening,'rek_nomor'); ?>

		<?php echo $form->textField($rekening,'rek_nomor',array('size'=>50,'maxlength'=>50)); ?>

		<?php echo $form->error($rekening,'rek_nomor'); ?>


	<div class="row">

		<?php echo $form->labelEx($rekening,'jenis_tabungan'); ?>

		<?php echo $form->dropDownList($rekening,'jenis_tabungan', $rekening->getJenisTabunganOptions()); ?>

		<?php echo $form->error($rekening,'jenis_tabungan'); ?>


<!-- Rekening data end //-->

	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>


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

The result is, below <h1>Data Rekening</h1> shown:

Fatal error: Call to a member function isAttributeRequired() on a non-object in C:\Program Files\xampp\htdocs\yii\framework\web\helpers\CHtml.php on line 1414

You do not pass the second model to the partial view ‘_form_create’.

In controller





in view

<?php echo $this->renderPartial('_form_create', array('model'=>$model,'rekening'=>$rekening)); ?>

Oh yeah, it’s work. Thank you.