CActiveForm and Model AR-Relation

Hi there :)

EDIT: Aaaah! Just found the solution: http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models!

I adapted my database structure to something more sophisticated with relations.

Before I had a members email address in the member table. Now I moved the email in the related table user.

In my controller I used


$model = new Member;

and in my view


<?php echo $form->textField($model, 'email') ?>

.

But this of course now gives me the error "Member.email not defined", because the field email is now in the table user.

How can I assign both Models to my view?

The relations are set up as follows:

Member Model:


	public function relations()

	{

		// Every member belongs to one user

		return array(

			'user' => array(self::BELONGS_TO, 'User', 'user_id'),

		);

	}

User Model:


	public function relations()

	{

		// Every user has one related table, either client or member

		return array(

			'member' => array(self::HAS_ONE, 'Member', 'user_id'),

		);

	}

Regards

ycast :)

to transmit 2 data model of view it means you put two models in the parameter.

like this:




$model=new Member;

$model2=new User;


// send model to view

 $this->render('create', array(

                    'model'=>$model,

                    'model2'=>$model2,

                ));




and in view just call such as:




<?php echo $form->textField($model, 'email') ?>

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