PHP 5.3+ and Yii 1.1.13+
You can use an anonymous function:
echo $form->dropDownListRow($model , 'client_id',
CHtml::listData(Client::model()->findAll(), 'id', function($data){
return $data->client_type_id == 1 ? $data->company_name : $data->first_name
})
);
Yii < 1.1.13 and/or PHP <5.3
You can use the CActiveRecord::afterFind()
method to initialize a variable say $list_info
and use this as your field:
class MyClass extends CActiveRecord{
public $list_info;
...
public function afterFind(){
$this->list_info=$this->client_type_id == 1 ? $this->company_name : $this->first_name
}
}
The drop down list then becomes
$form->dropDownListRow($model , 'client_id', CHtml::listData(
Client::model()->findAll(), 'id', 'list_info')
);
Reference: http://www.yiiframework.com/doc/api/1.1/CHtml#listData-detail