Retrieve multiple columns (attributes) from Model

I have a table with Families.

And I have at least this columns

id

LastName

Dad first name

Mom first name

And I need a DropDownList to show all Families.

Is there any way to concatenate thsi fields when creating the DropDownList ??


$form->dropDownList($model, 'fk_familia_id',  CHtml::listData(Familia::model()->findAll(),'id','apellido' ),array('prompt'=>'Select famlia'))

Options:

a) listData allows me to concatenate attribute values.

B) some way to create “transient” attributes to the model in onAfterFind event …

Any suggestion ?

Best Regards

In the model create a new method:




public function getMomDad()

{

    return $this->mom.' '.$this->dad;

}



Now you can use “momDad” attribute in CHtml::listData() ;)

A-MA-ZING !!!!!!!!

work like a charm, Many thanks dude !

This was one of the few things in my project driving me nuts. Thanks for the excellent tip! I tried it at first and it didn’t work but realized the attribute was case sensitive. First case lower when it was being called.

If there are number of other columns and sometime we need to change the order of the concatenated columns i.e DadMom or DadLastName etc, in that case we’ll be creating new functions for each? Any other solution than this?




public function getDadMom()

{

    return $this->dad.' '.$this->mom;

}



Now we can use “DadMom” attribute in CHtml::listData() ;)