Collect Data For Two Or More Models ( Get_Class() Expects Parameter 1 To Be Object, Array Given )

Hi everyone,

I see this Error when i called CreateController : "get_class() expects parameter 1 to be object, array given "

Controll/actionCreate() seen like that


public function actionCreate() {

	$model = new Ogrenci;

        $model2 =new Adresler;


	$this->performAjaxValidation($model, 'ogrenci-form');

        $this->performAjaxValidation($model2, 'ogrenci-form');


        if (isset($_POST['Ogrenci'],$_POST['Adresler'])) {

	    $model->setAttributes($_POST['Ogrenci']);

            $model2->setAttributes($_POST['Adresler']);


			if ($model->save(false) && $model2->save(false)) {

				if (Yii::app()->getRequest()->getIsAjaxRequest())

					Yii::app()->end();

				else

					$this->redirect(array('view', 'id' => $model->ogrenci_id));

			}

		}

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

    }

create.php


<?php


$this->renderPartial('_form', array(

    'model' => array('model'=>$model,'model2'=>$model2),

    'buttons' => 'create'));

?>

and _form.php’s fields seen like that


	<div class="row">

	<?php echo $form->labelEx($model2,'aciklama'); ?>

        <?php echo $form->textField($model2,'aciklama'); ?>

        <?php echo $form->error($model2,'aciklama'); ?>

	</div><!-- row -->

Thanks !

that is rather simple - second parameter to renderPartial is an associative array of parameters passed to rendered view. you assign there:


'model'=>array( 'model'=>$model, 'model2'=>$model2 )

change it to:


$this->renderPartial('_form', array(

    'model'=>$model,

    'model2'=>$model2,

    'buttons' => 'create')

);

thanks it works :)