concat first/last name for dropdownlist

I have a table called User with a first name and last name field. I’d like to make an activeDropDownList which uses the user_id field as the key and the concatenation of first and last name as the value.

My attempt looks like this:

$criteria = new CDbCriteria;

$criteria->select = 'user_id, concat(first_name, " ", last_name) as name';

echo CHtml::activeDropDownList($model, 'primary_contact_id', CHtml::listData(User::model()->findAll($criteria), 'user_id', 'name'));

Says it can’t find field name in User. Any thoughts?

in the User model class add an attribute

public $name;

And perhaps add

  protected function afterFind()


    $this->name = $this->first_name . ' ' . $this->last_name;




Never mind. Didn’t notice the criteria given.