Using A Function In Clistdata

Hi,

Im using ClistData to create an array from a database table, the problem is that I want to wrap the textfield within a function(mb_convert_encoding) to encode the characters but doesn’t seem to work. Look at the code below.





$Array = CHtml::listData(MyModel::model()->findAll(array('condition'=>'is_public = 1', 'order'=>'name ASC')),'user_id',mb_convert_encoding('name', 'utf-8', 'IBM-850'));




This code still outputs the wrong format on the characters. Is there another way to solve this?

All you’ve done is converted the encoding of the string ‘name’, not any of the content.

You probably need to build the array manually in this case:




$records = MyModel::model()->findAll(array('condition'=>'is_public = 1', 'order'=>'name ASC'));

$listData = array();

foreach ($records as $record)

{

    $listData[$record->user_id] = mb_convert_encoding($record->name, 'utf-8', 'IBM-850');

}



Good point! Works great, thanks!! :lol: