Show two table fields in dropDownlist

Hi everyone:)

At this moment I’m puzzled about something. In a form, I’m trying to display two databasefields as one textfield. These fields are retrieved correctly, but how can I chain them so they will display as one field in the dropdownlist?

Here’s the line of code I currently have:

<?php echo $form->dropDownlist($model,'machine_id',



                                      findAll(array('order'=>'merk.naam ASC')),

                                      'machine_id', 'merk.naam naam'),

                                      array('empty'=>'selecteer machine')); 


Obviously, a string like ‘merk.naam naam’ doesn’t work. Is there a way to display this correctly or should I solve this at model-level where the relation between the two tables is defined?

Thanks in advance,


Maybe a Yii trick exists I don’t know yet, but I would solve this at model level.

In Machine model, I would define a getter :

public function getCompleteMachineName ()


  return $this->merk->naam.' '.$this->naam;


And, il your listData :


  'machine_id', 'completeMachineName')

I think your solution (I have seen it before here in the forum like this) is the correct way to solve the problem the Yii way

Tof, Kokomo,

Thank you for the quick response! I will try this, much appreciated!