differentiate multiple instances of same model in a form

I have a design problem and want feedback form Yii community.

I have a form which has one or more person. Each person has a current address and one or more previous address.

At the moment, the way I set up is static,

for example

person1 has Person1 extend Person

person1 current address is CurrentAddrPerson1 extend Address

person1 previous address is PrevAddrPerson1 extend Address

person2 has Person2 extend Person

person2 current address is CurrentAddrPerson2 extend Address

person2 previous address is PrevAddrPerson2 extend Address

The reason I set up like this is in the view, I can do

<?php echo CHtml::activeTextField($person,"first_name"); ?>

which give me Person1[‘first_name’] or Person2[‘first_name’] depends on the $person passed in.

and

<?php echo CHtml::activeTextField($address,"street_name"); ?>

which give me CurrentAddrPerson1[‘street_name’] and CurrentAddrPerson2[‘street_name’]

Then on create/update action, I can do

$person1_model->attributes = $_POST[‘Person1’]

$person2_model->attributes = $_POST[‘Person2’]

and same with saving current/previous address.

The problem with this setup is the number of person and addresses are fixed. And I have to extend base model each time. For example, Person3 extend Person and Person4 extend Person.

I am looking for a solution that enable me to have as many person as possible without restriction.

I wonder if there are Yii hidden features or design patterns that I have not known.

Thanks.

For those who are interested, I’ve solved this problem by manually assign name field using ‘name’ option (e.g. $form->textField($model, attribute_name, array(‘name’ => ‘PrimaryApplicant[‘Person’][‘first_name’]’)

Maybe you should look at the tabular data stuff? http://www.yiiframework.com/doc/guide/1.1/en/form.table