Model Attributes Order

Somehow I need to use foreach loop to create my form from my Model (CActiveRecord).

So my form element order is depending on the attributes order.

The attributes order will mess up after the validation.

Lets say, print_r($model->attributes) for first time, the attributes order is like below,




Array ( [FirstName] => [LastName] => [PhoneNumber] => [Address] => )



After validation, print_r($model->attributes) again, the attributes order will become something like below,




Array ( [LastName] => [PhoneNumber] => [Address] => [FirstName] => )



This will make my form not consistent.

Any idea, how I can fix the attributes order?

Thank you.

I don’t think model attributes have an order.

Maybe you should think about the form element name.

I would add a method to your model, inside of which making a call to getTableSchema() with a further needed processing of data received.