CHtml::activeDropDown Option Labels

Hi,

I have a <select> list in a view that I’d like to populate with a list of employees from my DB. I’m using CHtml::activeDropDownList() and CHtml::listData() to accomplish this, and it looks like so:




<?php

      echo CHtml::activeDropDownList($model, deptHeadId, CHtml::listData(

        Employee::model()->findAll(), 'id', 'firstName'

      ));

?>



This works great, but I’d really like the employees’ first and last names to be displayed in the list. Since CHtml::listData() only takes a single model attribute for its third parameter, what would be the best way to accomplish it?

Would it be better to use afterFind() in the model, or to extend the CHtml class and overwrite the listData() method? Or is there an even better solution?

TIA very much!

Tom


<?php

      echo CHtml::activeDropDownList($model, deptHeadId, CHtml::listData(

        Employee::model()->findAll(), 'id', 'fullname'

      ));

?>

add follow function to your Employee model:


function getFullname()

{

    return $this->firstName, ' ', $this->lastName;

}

Oh, yeah. That’s way better. Thanks!